What is the alternative implementation of LocationClient in Google Play Service SDK 6.5?

Asked 2 years ago, Updated 2 years ago, 146 views

After updating the Google Play Service SDK to 6.5, LocationClient is no longer available.What should I do with the alternative implementation?

android google-play-service

2022-09-29 22:35

1 Answers

LocationClient has been deprecated and GoogleApiClient has been used instead.

public class MyActivity implements GoogleApiClient.ConnectionCallbacks,                   
                                   GoogleApiClient.OnConnectionFailedListener{
  private GoogleApiClient locationClient;

  protected void onCreate (Bundle bundle) {
    locationClient=new GoogleApiClient.Builder(ctx)
      .addApi (LocationServices.API)
      .addConnectionCallbacks (this)
      .addOnConnectionFailedListener(this)
      .build();
    locationClient.connect();
  }

  // Get the latest current location
  public Location getLastLocation(){
    LocationServices.FusedLocationApi.getLastLocation(locationClient);
  }
}

The above is a simplified example of code.

In addition, build.gradle is specified as follows:

compile'com.google.android.gms:play-services-location:6.5.+'


2022-09-29 22:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.