FusedLocationProviderApi.KEY_LOCATION_CHANGED 已弃用。现在要做什么?
FusedLocationProviderApi.KEY_LOCATION_CHANGED deprecated. What to do now?
我有一个 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 ***");
}
}
经过一番研究,我找到了答案:
@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
}
}
}
我有一个 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 ***");
}
}
经过一番研究,我找到了答案:
@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
}
}
}