LocationClient is deprecated. You have to use GoogleApiclient
, like this:
1: Declare a GoogleApiClient variable
private GoogleApiClient mGoogleApiClient;
2: Instantiate
mGoogleApiClient = new GoogleApiClient.Builder(mThisActivity)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
3: Implement Callback
public class YourClass extends BaseFragment implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener, LocationListener {
@Override
public void onConnectionFailed(ConnectionResult result) {
// your code goes here
}
@Override
public void onConnected(Bundle connectionHint) {
//your code goes here
}
@Override
public void onConnectionSuspended(int cause) {
//your code goes here
}
}
4: Start to get Location Updates:
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, this);
5: Remove Location Updates:
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
6: Get Last Known Location:
private Location mCurrentLocation;
mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);