android – What is the alternative implementation of LocationClient in Google Play Services SDK 6.5?

Question: Question:

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

Answer: Answer:

LocationClient has been deprecated and will now use Google ApiClient 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();
  }

  // 最新の現在地を取得
  public Location getLastLocation() {
    LocationServices.FusedLocationApi.getLastLocation(locationClient);
  }
}

The above is a simplified code example.

Also, specify the following in build.gradle .

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