Geocoder getFromLocationName()不起作用,返回0值

问题描述 投票:0回答:1

我想得到一个更接近传递的字符串的5个地址的列表,但有些东西不起作用。

例如,如果我写“avenida”,西班牙有成千上万的“avenida”街道,但方法getFromLocationName返回0。

private void getAddressInfo(Context context, String locationName){
        Geocoder geocoder = new Geocoder(context);
        try {
        List<Address> a = geocoder.getFromLocationName(locationName, 5);
        for(int i=0;i<a.size();i++){
            String city = a.get(0).getLocality();
            String country = a.get(0).getCountryName();
            String address = a.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
            addressList.add(address+", "+city+", "+country);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

代码中有什么问题吗?

android location android-location geocoder
1个回答
0
投票

我刚刚在代码中证实了这一点;它的工作方式是给它一个有效的地名,就像一个地址。它不需要一个城市。然后它应该给你一个尽可能多的列表。没有预期的那么有用。街道或商业名称似乎不起作用。 :-(

如果我做2000东部主要没有一个城市我得到一个打击

如果我做东主我得到0

I am going to use this instead

© www.soinside.com 2019 - 2024. All rights reserved.