Search in sources :

Example 11 with LocationResult

use of com.google.android.gms.location.LocationResult in project coursera-android by aporter.

the class LocationGetLocationActivity method getLocationCallback.

@NonNull
private LocationCallback getLocationCallback() {
    return new LocationCallback() {

        @Override
        public void onLocationResult(LocationResult locationResult) {
            ensureColor();
            // Get new location
            Location location = locationResult.getLastLocation();
            // Determine whether new location is better than current best estimate
            if (null == mBestReading || location.getAccuracy() < mBestReading.getAccuracy()) {
                // Update best location
                mBestReading = location;
                // Update display
                updateDisplay(location);
                // Turn off location updates if location reading is sufficiently accurate
                if (mBestReading.getAccuracy() < MIN_ACCURACY) {
                    mLocationClient.removeLocationUpdates(mLocationCallback);
                }
            }
        }
    };
}
Also used : LocationCallback(com.google.android.gms.location.LocationCallback) LocationResult(com.google.android.gms.location.LocationResult) Location(android.location.Location) NonNull(android.support.annotation.NonNull)

Aggregations

LocationResult (com.google.android.gms.location.LocationResult)11 Location (android.location.Location)10 LocationCallback (com.google.android.gms.location.LocationCallback)9 Intent (android.content.Intent)3 Handler (android.os.Handler)3 LocationRequest (com.google.android.gms.location.LocationRequest)3 HandlerThread (android.os.HandlerThread)2 GoogleApiClient (com.google.android.gms.common.api.GoogleApiClient)2 SupportMapFragment (com.google.android.gms.maps.SupportMapFragment)2 SuppressLint (android.annotation.SuppressLint)1 NotificationChannel (android.app.NotificationChannel)1 ProgressDialog (android.app.ProgressDialog)1 Message (android.os.Message)1 NonNull (android.support.annotation.NonNull)1 NavigationView (android.support.design.widget.NavigationView)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 AppCompatImageButton (android.support.v7.widget.AppCompatImageButton)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1