有了这个功能,我得到经度= 0和纬度= 0
我不知道问题出在哪里

private void getCurrentLocation() {

    Location location = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
    if (location != null) {
        //Getting longitude and latitude
        longitude = location.getLongitude();
        latitude = location.getLatitude();

        //moving the map to location
        moveMap();
    }
}

最佳答案

在Google API客户端提供的onConnected()回调中执行此操作,客户端准备就绪时会调用该回调。以下代码段说明了请求和响应的简单处理:

public class MainActivity extends ActionBarActivity implements
    ConnectionCallbacks, OnConnectionFailedListener {
...
@Override
public void onConnected(Bundle connectionHint) {
    mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
            mGoogleApiClient);
    if (mLastLocation != null) {
        mLatitudeText.setText(String.valueOf(mLastLocation.getLatitude()));
        mLongitudeText.setText(String.valueOf(mLastLocation.getLongitude()));
    }
}
}

09-26 12:15