gpt4 book ai didi

android - getLastKnownLocation() 返回 null

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:03:20 25 4
gpt4 key购买 nike

<分区>

我在 SO 上阅读了很多关于这个主题的问答,但我不得不说它们都不起作用。

我的问题是,即使我启用了 GPS,我也无法获取位置,除非我打开 Google map 并获取我的位置,然后返回应用程序,这绝对不是用户的选择。

我有以下函数来获取位置。

public Location getCurrentLocation() {
LocationManager locationManager = (LocationManager) context
.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
Location myLocation = locationManager.getLastKnownLocation(provider);

return myLocation;
}

关于如何解决这个问题,我是否遗漏了什么?我也试过这个 http://developer.android.com/training/location/retrieve-current.html#last-known但仍然返回 null。

提前致谢

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com