use of android.location.Location in project platform_frameworks_base by android.
the class CameraMetadataNative method getGpsLocation.
private Location getGpsLocation() {
String processingMethod = get(CaptureResult.JPEG_GPS_PROCESSING_METHOD);
double[] coords = get(CaptureResult.JPEG_GPS_COORDINATES);
Long timeStamp = get(CaptureResult.JPEG_GPS_TIMESTAMP);
if (areValuesAllNull(processingMethod, coords, timeStamp)) {
return null;
}
Location l = new Location(translateProcessToLocationProvider(processingMethod));
if (timeStamp != null) {
l.setTime(timeStamp);
} else {
Log.w(TAG, "getGpsLocation - No timestamp for GPS location.");
}
if (coords != null) {
l.setLatitude(coords[0]);
l.setLongitude(coords[1]);
l.setAltitude(coords[2]);
} else {
Log.w(TAG, "getGpsLocation - No coordinates for GPS location");
}
return l;
}
use of android.location.Location in project carat by amplab.
the class SamplingLibrary method getLastKnownLocation.
private static Location getLastKnownLocation(Context context, String provider) {
LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Location l = lm.getLastKnownLocation(provider);
return l;
}
use of android.location.Location in project robolectric by robolectric.
the class ShadowLocationManagerTest method simulateLocation_shouldNotNotifyListenerIfLessThanMinimumDistance.
@Test
public void simulateLocation_shouldNotNotifyListenerIfLessThanMinimumDistance() throws Exception {
TestLocationListener listener = new TestLocationListener();
locationManager.requestLocationUpdates(GPS_PROVIDER, 0, 200000, listener);
Location location1 = new Location(GPS_PROVIDER);
location1.setLatitude(1);
location1.setLongitude(2);
location1.setTime(0);
Location location2 = new Location(GPS_PROVIDER);
location2.setLatitude(1.5);
location2.setLongitude(2.5);
location2.setTime(1000);
shadowLocationManager.simulateLocation(location1);
shadowLocationManager.simulateLocation(location2);
assertThat(listener.location.getLatitude()).isEqualTo(1);
assertThat(listener.location.getLongitude()).isEqualTo(2);
}
use of android.location.Location in project robolectric by robolectric.
the class ShadowLocationManagerTest method simulateLocation_shouldNotNotifyListenerIfLessThanFastestInterval.
@Test
public void simulateLocation_shouldNotNotifyListenerIfLessThanFastestInterval() throws Exception {
TestLocationListener listener = new TestLocationListener();
shadowLocationManager.requestLocationUpdates(GPS_PROVIDER, 2000, 0, listener);
long time = System.currentTimeMillis();
Location location1 = new Location(GPS_PROVIDER);
location1.setTime(time);
Location location2 = new Location(GPS_PROVIDER);
location2.setTime(time + 1000);
shadowLocationManager.simulateLocation(location1);
shadowLocationManager.simulateLocation(location2);
assertThat(listener.location.getTime()).isEqualTo(location1.getTime());
}
use of android.location.Location in project robolectric by robolectric.
the class ShadowLocationManagerTest method shouldReturnLastKnownLocationForAProvider.
@Test
public void shouldReturnLastKnownLocationForAProvider() throws Exception {
assertNull(locationManager.getLastKnownLocation(NETWORK_PROVIDER));
Location networkLocation = new Location(NETWORK_PROVIDER);
Location gpsLocation = new Location(GPS_PROVIDER);
shadowLocationManager.setLastKnownLocation(NETWORK_PROVIDER, networkLocation);
shadowLocationManager.setLastKnownLocation(GPS_PROVIDER, gpsLocation);
assertSame(locationManager.getLastKnownLocation(NETWORK_PROVIDER), networkLocation);
assertSame(locationManager.getLastKnownLocation(GPS_PROVIDER), gpsLocation);
}
Aggregations