Example usage for android.location LocationManager getLastLocation

List of usage examples for android.location LocationManager getLastLocation

Introduction

In this page you can find the example usage for android.location LocationManager getLastLocation.

Prototype

public Location getLastLocation() 

Source Link

Document

Get the last known location.

Usage

From source file:com.google.android.dialer.provider.DialerProvider.java

private Location getLastLocation() {
    LocationManager locationManager = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestSingleUpdate(new Criteria(), new LocationListener() {
        @Override//from  w w w  .  ja va 2s  .c o m
        public void onLocationChanged(Location location) {
            if (Log.isLoggable("DialerProvider", Log.VERBOSE)) {
                Log.v("DialerProvider", "onLocationChanged: " + location);
            }
        }

        @Override
        public void onProviderDisabled(String provider) {
            if (Log.isLoggable("DialerProvider", Log.VERBOSE)) {
                Log.v("DialerProvider", "onProviderDisabled: " + provider);
            }
        }

        @Override
        public void onProviderEnabled(String provider) {
            if (Log.isLoggable("DialerProvider", Log.VERBOSE)) {
                Log.v("DialerProvider", "onProviderEnabled: " + provider);
            }
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
            if (Log.isLoggable("DialerProvider", Log.VERBOSE)) {
                Log.v("DialerProvider", "onStatusChanged: " + provider + ", " + status + ", " + extras);
            }
        }
    }, DialerProvider.mLooper);
    return locationManager.getLastLocation();
}