我所做的就是实现com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks,OnConnectionFailedListener。 创建GoogleApiClient场,并呼吁从的onCreate
protected synchronized void buildGoogleApiClient() {
Toast.makeText(this, "buildGoogleApiClient", Toast.LENGTH_SHORT).show();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API).build();
mGoogleApiClient.connect();
}
下面的方法,你的活动上面接口来实现的,你将有以下方法,并从onConnected你可以得到当前的位置
public void onConnectionFailed(ConnectionResult arg0) {
Toast.makeText(this, "connection failed", Toast.LENGTH_SHORT).show();
}
@Override
public void onConnected(Bundle arg0) {
Toast.makeText(this, "in onconnected of location services",
Toast.LENGTH_SHORT).show();
mLastLocation = LocationServices.FusedLocationApi
.getLastLocation(mGoogleApiClient);
}
可以使用mLastLocation .getLatitude和.getLongitude
这对您有帮助吗?如果是这样,请接受,谢谢 – bjiang 2015-05-20 16:26:25