Android Geocoder和Google Geocoding网络服务之间的结果不同

Different results between Android Geocoder and Google Geocoding web service

我正在创建一个Android应用程序,我需要使用地理位置。

我已经开始使用Android(Geocoder)的Geocoder API(android.location.geocoder),但这会导致一些问题(等待服务器的响应超时),根据我所阅读的内容,这似乎很常见。

为了使我的应用程序在发生此类错误时能够正常工作,我使用了地理编码Web服务。

现在,该应用程序每次都可以运行。问题是地理编码器从API返回的结果与地理编码器从Web服务返回的结果不同。

例如,Web服务仅返回3个地址,仅包含城市名称和国家/地区,而API的地理编码返回大约8个地址,其中包含功能名称,通途,地点...

问题是:有没有办法使Web服务的结果与API的结果完全相同?

编辑

这是我的MainGeocoder类:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class MainGeocoder {

    private Geocoder geocoderAPI;
    private GeocoderRest geocoderRest;

    public MainGeocoder(Context context) {
        geocoderAPI = new Geocoder(context);
        geocoderRest = new GeocoderRest(context);
    }

    public List<Address> getFromLocationName(String search, int maxResults) {
        List<Address> addresses;
        try {
            addresses = geocoderAPI.getFromLocationName(search, maxResults);
            return addresses;
        } catch (IOException e) {
            e.printStackTrace();
            try {
                addresses = geocoderRest.getFromLocationName(search, maxResults);
                return addresses;
            } catch (IOException e1) {
                return null;
            } catch (LimitExceededException e1) {
                return null;
            }
        }
    }
}

基本上,它尝试从API Geocoder获取地址列表。如果发生IO异常,它将使用从此处粘贴的GeocoderRest类从Web服务获取此列表:https://stackoverflow.com/a/15117087/3571822


Is there a way to make the results from the web service exactly the
same than the ones from the API?

完全没有。在大多数尝试中,这两种地理编码器之间总会有区别。由于android.location.Geocoder内部使用服务,您无法在源代码中进行跟踪,因此您永远不会问确切的区别在哪里,而要询问Google。而且我认为他们不会提供此信息。

顺便说一句,您使用的GeocoderRest类甚至不会解析响应中包含的一半信息。通常,Web服务比SDK中的API更可靠。