我有一个LocationReceiver,它使用FusedLocationProviderApi.KEY_LOCATION_CHANGED从Intent中提取Location。但是现在KEY_LOCATION_CHANGED被否决了,我应该把它更改为什么呢?
当前代码:
@Override
public void onReceive(Context context, Intent intent) {
final Location location = (Location) intent.getExtras().get(FusedLocationProviderApi.KEY_LOCATION_CHANGED);
if (location != null) {
float accuracy = location.getAccuracy();
Log.d(LocationReceiver.class.getSimpleName(), "*** Accuracy is: " + accuracy + " ***");
} else {
Log.d(LocationReceiver.class.getSimpleName(), "*** location object is null ***");
}
}发布于 2016-01-28 09:23:45
经过一番研究,我找到了答案:
@Override
public void onReceive(Context context, Intent intent) {
if (LocationResult.hasResult(intent)) {
LocationResult locationResult = LocationResult.extractResult(intent);
Location location = locationResult.getLastLocation();
if (location != null) {
// use the Location
}
}
}https://stackoverflow.com/questions/35057405
复制相似问题