1

I noticed that it's possible to request location updates in (at least) two different ways.

  1. Using GoogleAPIClient:

    // Callback for when the GoogleAPIClient is connected
    @Override
    public void onConnected(Bundle connectionHint) {
        LocationServices.FusedLocationApi.requestLocationUpdates(
            mGoogleApiClient, mLocationRequest, this);
    }
    

 

  1. Using LocationManager:

    LocationManager locationManager = (LocationManager) getActivity().
        getSystemService(Context.LOCATION_SERVICE);      
    
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 
        0, 0, locationListener);
    

 

Google seems to promote method 1 in their tutorial "Receiving Location Updates". It's unclear to me what the benefit of method 1 is, because method 2 is working just as fine for me (I'm using both methods in two different places in an app).

Magnus
  • 17,157
  • 19
  • 104
  • 189
  • Check this answer, too [link](http://stackoverflow.com/questions/37395614/locationmanager-uses-fusedlocationproviderapi/37396211#37396211) – blackkara May 28 '16 at 13:30

2 Answers2

2

Good news, from Google Play Services version 11.0, no need to connect GoogleApiClient

https://android-developers.googleblog.com/2017/06/reduce-friction-with-new-location-apis.html

You don't have to handle callbacks and states(connected, connecting), just request/remove location updates, similar taste of LocationManager.

blackkara
  • 4,900
  • 4
  • 28
  • 58
1

The new method to get location updates is to use Fused Location Provider in android. The best thing about Fused location provider API is that you not need to worry about location updates it gives you always latest and accurate location and updates location after a interval or on location change . One more thing about Fused location provider API is you don't need to think about best location provider because it automatically choose best one suited for your hardware of your android device.

Here is a YouTube Video in I/O 2013, which may provide more details.

Alex Chengalan
  • 8,211
  • 4
  • 42
  • 56