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
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.+'
© 2024 OneMinuteCode. All rights reserved.