【发布时间】:2015-10-14 09:11:20
【问题描述】:
我正在使用 Google 服务 API、LocationServices.FusedLocationApi 来查找用户的当前位置,然后再更新位置。我已经在模拟器和实际设备上进行了测试,我发现如果我关闭 GPS LocationServices.FusedLocationApi.getLastLocation() 总是返回 null,但是如果我打开 GPS,我会得到一个有效值。这是我正在使用的代码:
private GoogleApiClient mGoogleApiClient;
private Location mLastKnownLocation;
mLastKnownLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if (mLastKnownLocation != null) {
Log.i(TAG, String.valueOf(mLastKnownLocation.getLatitude()));
Log.i(TAG, String.valueOf(mLastKnownLocation.getLongitude()));
}
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, createLocationRequest(), this);
我在这里遗漏了什么吗? 提前致谢。
【问题讨论】:
标签: android android-emulator gps google-play-services location-services