LocationClient không được dùng nữa. Bạn phải sử dụng GoogleApiclient
, như thế này:
1: Khai báo một biến GoogleApiClient
private GoogleApiClient mGoogleApiClient;
2: Khởi tạo
mGoogleApiClient = new GoogleApiClient.Builder(mThisActivity)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
3: Thực hiện gọi lại
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: Bắt đầu để nhận thông tin cập nhật vị trí:
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, this);
5: Di chuyển Location Cập nhật:
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
6: Nhận Last Known Location:
private Location mCurrentLocation;
mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
Nguồn
2015-07-10 20:01:38
Tôi chỉ cập nhật "dịch vụ bổ sung \ google play" thông qua "Trình quản lý SDK Android", tôi tìm thấy tệp "google-play-services.jar" mới nhất chứa tệp "LocationClient.class"; (và tệp "google-play-services.jar" cũ chỉ được tải xuống cách đây 5 ngày) –