Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android play services 6.5: LocationClient is missing

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..

like image 942
Volkman Avatar asked Dec 09 '14 06:12

Volkman


1 Answers

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());
        }
   }
});
like image 149
ianhanniballake Avatar answered Oct 23 '22 06:10

ianhanniballake