3

我有一个LocationReceiver用于FusedLocationProviderApi.KEY_LOCATION_CHANGED从. 但是现在已弃用我应该将其更改为什么?LocationIntentKEY_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 ***");
    }
}
4

1 回答 1

17

经过一番研究,我找到了答案:

@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
        }
    }
}
于 2016-01-28T09:23:45.187 回答