gpt4 book ai didi

android - Genymotion - 从经度和纬度获取地址

转载 作者:行者123 更新时间:2023-11-29 17:49:57 25 4
gpt4 key购买 nike

我使用此代码获取我当前的地址:

public String getAdressFromLongLat(double lati, double longi) {
List<Address> addresses = new ArrayList<Address>();
Geocoder geocoder = new Geocoder(mContext,Locale.getDefault());

try {
addresses = geocoder.getFromLocation(lati, longi, 1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
if(addresses==null || addresses.size()<=0) {
return null;
}
String address = addresses.get(0).getAddressLine(0);
String city = addresses.get(0).getAddressLine(1);
return address + "/;/" + city;
}

但它每次都返回 null。我没有真正的设备,所以我在 genymotion 模拟器中进行测试。这是问题吗?还是代码有问题?

-> 我用调试器找到了问题:地址不为空,但大小为 0,为什么? :(

最佳答案

Genymotion 可能不支持地址查找。来自official documentation :

Note: Address lookup requires a backend service that is not included in the core Android framework. If this backend service is not available, Geocoder.getFromLocation() returns an empty list. The helper method isPresent(), available in API level 9 and later, checks to see if the backend service is available.

尝试调用 Geocoder.isPresent()可以肯定。

关于android - Genymotion - 从经度和纬度获取地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23594485/

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