45

After updating to Google Play Services 6.5.87 my app was failed to compile because of missing LocationCLient class.

The documentation link is corrupted at the moment (404 Not Found)

How can I fix it? I want to receive location updates, work with geofences, etc..

Ranjit
  • 5,130
  • 3
  • 30
  • 66
Volkman
  • 902
  • 1
  • 8
  • 19

1 Answers1

56

The LocationClient class has been replaced with the new FusedLocationProviderApi and the GeofencingApi, both of which use the common GoogleApiClient connection technique to connect to Google Play Services. Once you are connected, you can call methods such as requestLocationUpdates():

LocationRequest locationRequest = LocationRequest.create()
    .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

PendingResult<Status> result = LocationServices.FusedLocationApi
    .requestLocationUpdates(
        googleApiClient,   // your connected GoogleApiClient
        locationRequest,   // a request to receive a new location
        locationListener); // the listener which will receive updated locations

// Callback is asynchronous. Use await() on a background thread or listen for
// the ResultCallback
result.setResultCallback(new ResultCallback<Status>() {
    void onResult(Status status) {
        if (status.isSuccess()) {
            // Successfully registered
        } else if (status.hasResolution()) {
            // Google provides a way to fix the issue
            status.startResolutionForResult(
                activity,     // your current activity used to receive the result
                RESULT_CODE); // the result code you'll look for in your
                              // onActivityResult method to retry registering
        } else {
            // No recovery. Weep softly or inform the user.
            Log.e(TAG, "Registering failed: " + status.getStatusMessage());
        }
   }
});
ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • 3
    Thanks! Looks like they updated the services but forgot to update the documentation. – Redwarp Dec 09 '14 at 09:29
  • I'm curious as to what this means for applications in the field that are using the now removed LocationClient API, and what happens when the user's phone updates to the latest Google Play Services? Since the API no longer compiles -- do the applications crash or keep working? – Alchete Dec 09 '14 at 15:15
  • 6
    @Alchete - apps compiled against previous versions of the Google Play Services SDK will continue to work (this can easily be verified as every phone has 6.5 yet not every app has updated to the new APIs) – ianhanniballake Dec 09 '14 at 15:37
  • 5
    I really wish google would update their documentation. The sample LocationProvider app from their website no longer works: https://developer.android.com/training/location/location-testing.html – Simon Dec 28 '14 at 19:10
  • 2
    @Simon - the latest Google Location samples can be found [on Github](https://github.com/googlesamples/android-play-location). Not sure why the samples on the Developer site still point to the old ones. – ianhanniballake Dec 30 '14 at 06:02