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

标签 android google-geocoder genymotion

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

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/

相关文章:

java - Android 计时器不添加秒数

android - 使用折线和数组列表在 map 中添加多个点

android - MPAndroidChart 饼图 : not showing all labels

android - 实现 Geocoder 时返回 null

android - 找不到参数的方法 android()

Android:如何在 MapView 上执行附近搜索

android - 英语而不是 Geocoder 的本地语言

java - FontAwesome 图标不会显示在 Android 应用程序上

macos - Android 模拟器 GenyMotion(带 VirtualBox)导致 New 1 3'' Macbook Pro Yosemite 10.10.2 崩溃

path - 如何更改Genymotion的虚拟设备路径?