Search in sources :

Example 31 with Location

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;
}
Also used : MarshalQueryableString(android.hardware.camera2.marshal.impl.MarshalQueryableString) Location(android.location.Location)

Example 32 with Location

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;
}
Also used : LocationManager(android.location.LocationManager) GsmCellLocation(android.telephony.gsm.GsmCellLocation) CellLocation(android.telephony.CellLocation) Location(android.location.Location) CdmaCellLocation(android.telephony.cdma.CdmaCellLocation)

Example 33 with Location

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);
}
Also used : Location(android.location.Location) Test(org.junit.Test)

Example 34 with Location

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());
}
Also used : Location(android.location.Location) Test(org.junit.Test)

Example 35 with Location

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);
}
Also used : Location(android.location.Location) Test(org.junit.Test)

Aggregations

Location (android.location.Location)290 Bundle (android.os.Bundle)50 LocationListener (android.location.LocationListener)38 LocationManager (android.location.LocationManager)33 ArrayList (java.util.ArrayList)29 Criteria (android.location.Criteria)20 LocationProviderInterface (com.android.server.location.LocationProviderInterface)18 GsmCellLocation (android.telephony.gsm.GsmCellLocation)17 BluetoothAdapter (android.bluetooth.BluetoothAdapter)12 BroadcastReceiver (android.content.BroadcastReceiver)12 Handler (android.os.Handler)10 MockProvider (com.android.server.location.MockProvider)9 Intent (android.content.Intent)8 Timer (java.util.Timer)8 Test (org.junit.Test)8 PendingIntent (android.app.PendingIntent)7 IOException (java.io.IOException)7 LocationProviderProxy (com.android.server.location.LocationProviderProxy)6 HashMap (java.util.HashMap)6 List (java.util.List)6