首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FusedLocationProviderApi.KEY_LOCATION_CHANGED不赞成。现在该怎么办?

FusedLocationProviderApi.KEY_LOCATION_CHANGED不赞成。现在该怎么办?
EN

Stack Overflow用户
提问于 2016-01-28 09:21:26
回答 1查看 1.7K关注 0票数 3

我有一个LocationReceiver,它使用FusedLocationProviderApi.KEY_LOCATION_CHANGEDIntent中提取Location。但是现在KEY_LOCATION_CHANGED被否决了,我应该把它更改为什么呢?

当前代码:

代码语言:javascript
复制
@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 ***");
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-28 09:23:45

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

代码语言:javascript
复制
@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
        }
    }
}
票数 17
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35057405

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档