本文整理汇总了Java中android.location.Location类的典型用法代码示例。如果您正苦于以下问题:Java Location类的具体用法?Java Location怎么用?Java Location使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Location类属于android.location包,在下文中一共展示了Location类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onMapReady
import android.location.Location; //导入依赖的package包/类
@Override
public synchronized void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Start position marker
mMap.addMarker(new MarkerOptions().
position(startCoordinate).
icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));
// end position marker
mMap.addMarker(new MarkerOptions().
position(endCoordinate).
icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
if(objectLocations!=null)
for(com.nctu.bikeline.Model.Location objLocation:objectLocations){
mMap.addMarker(new MarkerOptions().position(objLocation.getCoordinate())
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
}
// highlight route
mMap.addPolyline(options);
// move and zoom camera
if(gpsService != null)
updateDirectionOverlay(gpsService.getLocation(), 0, false);
}
示例2: getLastKnownLocation
import android.location.Location; //导入依赖的package包/类
private Location getLastKnownLocation() {
mLocationManager = (LocationManager)InstrumentationRegistry.getTargetContext().getSystemService(LOCATION_SERVICE);
List<String> providers = mLocationManager.getProviders(true);
Location bestLocation = null;
for (String provider : providers) {
Location loc;
try{
loc = mLocationManager.getLastKnownLocation(provider);
} catch (SecurityException e) {
loc = null;
}
if (loc == null) {
continue;
}
if (bestLocation == null || loc.getAccuracy() < bestLocation.getAccuracy()) {
// Found best last known location: %s", l);
bestLocation = loc;
}
}
return bestLocation;
}
示例3: onReceive
import android.location.Location; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
prefs = Utils.getPrefs(context);
switch (intent.getAction()) {
case Intent.ACTION_BOOT_COMPLETED:
case ACTION_START_LOCATION:
apiClient = new GoogleApiClient.Builder(context)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
apiClient.connect();
break;
case ACTION_LOCATION_UPDATE:
if (prefs.getBoolean(Common.PREF_ENABLE_LOCATION_TRACKING, false) && LocationResult.hasResult(intent)) {
LocationResult result = LocationResult.extractResult(intent);
Location location = result.getLastLocation();
if (location != null)
logLocation(location, context);
}
break;
}
}
示例4: getLastLocation
import android.location.Location; //导入依赖的package包/类
@SuppressWarnings("MissingPermission")
private void getLastLocation() {
mFusedLocationClient.getLastLocation()
.addOnCompleteListener((Activity) getContext(), new OnCompleteListener<Location>() {
@Override
public void onComplete(@NonNull Task<Location> task) {
if (task.isSuccessful() && task.getResult() != null) {
mLastLocation = task.getResult();
Toast.makeText(getContext(), "Location set", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getContext(), "Location not set", Toast.LENGTH_SHORT).show();
}
}
});
}
示例5: checksSendEventNotCalledWhenAltitudeNaN
import android.location.Location; //导入依赖的package包/类
@Test
public void checksSendEventNotCalledWhenAltitudeNaN() throws Exception {
Context mockedContext = mock(Context.class);
Intent mockedIntent = mock(Intent.class);
when(mockedIntent.getStringExtra(eq("location_received"))).thenReturn("onLocation");
Bundle mockedBundle = mock(Bundle.class);
when(mockedIntent.getExtras()).thenReturn(mockedBundle);
Location mockedLocation = mock(Location.class);
when(mockedBundle.get(eq(LocationManager.KEY_LOCATION_CHANGED))).thenReturn(mockedLocation);
when(mockedLocation.getAltitude()).thenReturn(Double.NaN);
EventSender mockedEventSender = mock(EventSender.class);
LocationReceiver theLocationReceiver = new LocationReceiver(mockedEventSender);
theLocationReceiver.onReceive(mockedContext, mockedIntent);
verify(mockedEventSender, never()).send(any(LocationEvent.class));
}
示例6: findStationNearly
import android.location.Location; //导入依赖的package包/类
private void findStationNearly() {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
{
// Sur Défaut, l'on force la localisation de "FDF - Lycée Bellevue"
stationMadininair= new StationsMadininair(14.602902, 61.077537);
tvStationNearly.setText(R.string.find_station_error);
} else
{
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
//TODO: a controler si cela fonctionne avec d'autres périphériques
Location loc = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
stationMadininair= new StationsMadininair(loc.getLatitude(), loc.getLongitude());
tvStationNearly.setText(String.format("%s : %s",
getString(R.string.display_station_nearly),
Utilites.recupNomStation(stationMadininair.getNumStationNearly())));
}
}
示例7: locationCompatibleWithGroup
import android.location.Location; //导入依赖的package包/类
/**
* Check to see if the coverage area (location) of an RF emitter is close
* enough to others in a group that we can believably add it to the group.
* @param location The coverage area of the candidate emitter
* @param locGroup The coverage areas of the emitters already in the group
* @param radius The coverage radius expected for they type of emitter
* we are dealing with.
* @return
*/
private boolean locationCompatibleWithGroup(Location location,
Set<Location> locGroup,
double radius) {
// If the location is within range of all current members of the
// group, then we are compatible.
for (Location other : locGroup) {
double testDistance = (location.distanceTo(other) -
location.getAccuracy() -
other.getAccuracy());
if (testDistance > radius) {
return false;
}
}
return true;
}
示例8: onReceiveResult
import android.location.Location; //导入依赖的package包/类
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
if (resultCode == FetchLocationIntentService.SUCCESS_RESULT) {
LatLng latLng = resultData.getParcelable(FetchLocationIntentService.RESULT_DATA_KEY);
if (latLng == null)
return;
defaultLocation.setLatitude(latLng.latitude);
defaultLocation.setLongitude(latLng.longitude);
Log.d(TAG, "Geocoding for Country Name Successful: " + latLng.toString());
if (mMap != null) {
if (defaultLocation.getLatitude() != 0.0 || defaultLocation.getLongitude() != 0.0)
zoomLevel = 16.9f;
// Check if any Location Data is available, meaning Country zoom level need not be used
Location lastKnownCachedLocation = SharedPreferenceManager.getLastKnownLocation(Home.this);
if (lastKnownCachedLocation != null && lastKnownCachedLocation.getLatitude() != 0.0
&& lastKnownCachedLocation.getLongitude() != 0.0) {
return;
}
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, zoomLevel));
}
}
}
示例9: onLocationChanged
import android.location.Location; //导入依赖的package包/类
@Override
public void onLocationChanged(Location location) {
//place marker at current position
//mGoogleMap.clear();
if (currLocationMarker != null) {
currLocationMarker.remove();
}
latLng = new LatLng(location.getLatitude(), location.getLongitude());
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title(getString(R.string.current_position));
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA));
currLocationMarker = mGoogleMap.addMarker(markerOptions);
//zoom to current position:
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(latLng).zoom(14).build();
mGoogleMap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
mMocketClient.pushLatLngToServer(latLng);
}
示例10: FromProperties
import android.location.Location; //导入依赖的package包/类
@Override
public void FromProperties(SoapObject so) {
Comment = ReadNullableString(so, "Comment");
VirtualPath = ReadNullableString(so, "VirtualPath");
URLFullImage = ReadNullableString(so, "URLFullImage");
ThumbnailFile = ReadNullableString(so, "ThumbnailFile");
Width = Integer.parseInt(so.getProperty("Width").toString());
Height = Integer.parseInt(so.getProperty("Height").toString());
WidthThumbnail = Integer.parseInt(so.getProperty("WidthThumbnail").toString());
HeightThumbnail = Integer.parseInt(so.getProperty("HeightThumbnail").toString());
if (so.hasProperty("Location")) {
SoapObject location = (SoapObject) so.getProperty("Location");
Location = new LatLong();
Location.FromProperties(location);
}
if (so.hasProperty("ImageType"))
ImageType = ImageFileType.valueOf(so.getProperty("ImageType").toString());
}
示例11: getCurPos
import android.location.Location; //导入依赖的package包/类
private void getCurPos () {
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
mFusedLocationClient.getLastLocation()
.addOnSuccessListener(this, new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
// Got last known location. In some rare situations this can be null.
if (location != null) {
start = new LatLng(location.getLatitude(), location.getLongitude());
if (info == null)
info = getAddress(MapsActivity2.this, location.getLatitude(), location.getLongitude());
moveToPosition();
}
}
})
.addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(MapsActivity2.this, "Check Your GPS or network", Toast.LENGTH_SHORT).show();
}
});
}
示例12: onOwnLocationReceived
import android.location.Location; //导入依赖的package包/类
/**** START OwnLocationReceivedListener ****/
@Override
public void onOwnLocationReceived(final Location location) {
logStatus("Own location received: Lon: " + GPS_COORD_FORMAT.format(location.getLongitude()) + ", Lat: " + GPS_COORD_FORMAT.format(location.getLatitude()));
lastReceivedOwnLocation=location;
if (getActivity()!=null){
getActivity().runOnUiThread(new Runnable() {
public void run() {
webView.loadUrl("javascript:setCurrentPosition(" + location.getLongitude() + "," + location.getLatitude() + ")");
}
});
} else {
Log.e(TAG,"Huh?");
}
}
示例13: LocationRepository
import android.location.Location; //导入依赖的package包/类
public LocationRepository(Activity activity, GoogleApiClient mGoogleApiClient) {
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(activity);
this.mGoogleApiClient = mGoogleApiClient;
mFusedLocationClient.getLastLocation()
.addOnSuccessListener(activity, new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
if (location != null) {
userLocation = location;
publishSubject.onNext(userLocation);
//addOverlay(new LatLng(userLocation.getLatitude(), userLocation.getLongitude()));
//mMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
} else {
userLocation = null;
}
}
});
}
示例14: onRequestPermissionsResult
import android.location.Location; //导入依赖的package包/类
@Override
@SuppressWarnings({"MissingPermission"})
public void onRequestPermissionsResult(int requestCode,
@NonNull String permissions[],
@NonNull int[] grantResults) {
switch (requestCode) {
case PERMISSION_REQUEST_ACCESS_FINE_LOCATION_SHOW_ICON_IN_MAP:
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
setUpMap();
}
break;
case PERMISSION_REQUEST_ACCESS_FINE_LOCATION_GET_LAST_LOCATION:
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Location lastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if (lastLocation != null) {
moveCameraToLocation(lastLocation);
}
}
}
}
示例15: onLocationChanged
import android.location.Location; //导入依赖的package包/类
@Override
public void onLocationChanged(Location location) {
mLastLocation = location;
//remove previous current location Marker
if (marker != null) {
marker.remove();
}
current_Latitude = mLastLocation.getLatitude();
current_Longitude = mLastLocation.getLongitude();
marker = mMap.addMarker(new MarkerOptions().position(new LatLng(current_Latitude, current_Longitude))
.title("My Location").icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(current_Latitude, current_Longitude), 8));
}