Search in sources :

Example 26 with Location

use of android.location.Location in project robolectric by robolectric.

the class ShadowLocationManager method copyOf.

private Location copyOf(Location location) {
    if (location == null)
        return null;
    Location copy = new Location(location);
    copy.setAccuracy(location.getAccuracy());
    copy.setAltitude(location.getAltitude());
    copy.setBearing(location.getBearing());
    copy.setExtras(location.getExtras());
    copy.setLatitude(location.getLatitude());
    copy.setLongitude(location.getLongitude());
    copy.setProvider(location.getProvider());
    copy.setSpeed(location.getSpeed());
    copy.setTime(location.getTime());
    return copy;
}
Also used : Location(android.location.Location)

Example 27 with Location

use of android.location.Location in project Android-FusedLocation by levelup.

the class FusedCriteriaTest method testDefaultCriteria.

public void testDefaultCriteria() throws InterruptedException {
    final CountDownLatch signal = new CountDownLatch(1);
    Criteria criteria = new Criteria();
    locationManager.requestLocationUpdates(MIN_TIME_IN_MS, MIN_DISTANCE_IN_M, criteria, new LocationListener() {

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

        @Override
        public void onProviderDisabled(String provider) {
        }

        @Override
        public void onLocationChanged(Location location) {
            assertNotNull(location);
            signal.countDown();
        }
    }, null);
    signal.await(MIN_TIME_IN_MS, TimeUnit.MILLISECONDS);
}
Also used : Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) Criteria(android.location.Criteria) CountDownLatch(java.util.concurrent.CountDownLatch) Location(android.location.Location)

Example 28 with Location

use of android.location.Location in project coursera-android by aporter.

the class LocationGetLocationActivity method bestLastKnownLocation.

// Get the last known location from all providers
// return best reading that is as accurate as minAccuracy and
// was taken no longer then minAge milliseconds ago. If none,
// return null.
private Location bestLastKnownLocation(float minAccuracy, long maxAge) {
    Location bestResult = null;
    float bestAccuracy = Float.MAX_VALUE;
    long bestAge = Long.MIN_VALUE;
    List<String> matchingProviders = mLocationManager.getAllProviders();
    for (String provider : matchingProviders) {
        Location location = mLocationManager.getLastKnownLocation(provider);
        if (location != null) {
            float accuracy = location.getAccuracy();
            long time = location.getTime();
            if (accuracy < bestAccuracy) {
                bestResult = location;
                bestAccuracy = accuracy;
                bestAge = time;
            }
        }
    }
    // Return best reading or null
    if (bestAccuracy > minAccuracy || (System.currentTimeMillis() - bestAge) > maxAge) {
        return null;
    } else {
        return bestResult;
    }
}
Also used : Location(android.location.Location)

Example 29 with Location

use of android.location.Location in project facebook-android-sdk by facebook.

the class PlacePickerFragment method setSettingsFromBundle.

@Override
public void setSettingsFromBundle(Bundle inState) {
    super.setSettingsFromBundle(inState);
    if (inState != null) {
        setRadiusInMeters(inState.getInt(RADIUS_IN_METERS_BUNDLE_KEY, radiusInMeters));
        setResultsLimit(inState.getInt(RESULTS_LIMIT_BUNDLE_KEY, resultsLimit));
        if (inState.containsKey(SEARCH_TEXT_BUNDLE_KEY)) {
            setSearchText(inState.getString(SEARCH_TEXT_BUNDLE_KEY));
        }
        if (inState.containsKey(LOCATION_BUNDLE_KEY)) {
            Location location = inState.getParcelable(LOCATION_BUNDLE_KEY);
            setLocation(location);
        }
        showSearchBox = inState.getBoolean(SHOW_SEARCH_BOX_BUNDLE_KEY, showSearchBox);
    }
}
Also used : Location(android.location.Location)

Example 30 with Location

use of android.location.Location in project AndroidSDK-RecipeBook by gabu.

the class Recipe073 method onResume.

@Override
protected void onResume() {
    super.onResume();
    // 現在の状況に最適なプロバイダを取得します。
    // Criteriaで細かい条件が指定できますが今回はデフォルトで
    String provider;
    provider = mManager.getBestProvider(new Criteria(), true);
    if (provider == null) {
    // 位置情報が取得できるプロバイダがありません。
    // Wifiにも3Gにも繋がっていないなど。
    }
    mManager.requestLocationUpdates(provider, 0, 0, this);
    // 最後に取得した位置情報を取得
    Location location = mManager.getLastKnownLocation(provider);
    if (location != null)
        onLocationChanged(location);
}
Also used : Criteria(android.location.Criteria) Location(android.location.Location)

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