Different results between Android Geocoder and Google Geocoding web service
Asked Answered
B

1

6

I am creating an Android application and I need to use the geolocation.

I have started by using the Geocoder API from Android (android.location.geocoder) but it causes some issues (timed out waiting for response from server) which seems to be common according to what I have read.

To make my application work when this kind of error occurs, I use the Geocoding web service.

Now, the application works every time. The problem is that the results returned by the geocoder from API and the geocoder from the web service are not the same.

For example the web service returns only 3 addresses with only city name and country whereas the geocoding from the API returns about 8 addresses with the feature name, the thoroughfare, the locality...

The question is: is there a way to make the results from the web service exactly the same than the ones from the API?

EDIT

Here is my MainGeocoder class:

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;
            }
        }
    }
}

It basically tries to get the list of addresses from the API Geocoder. If an IO exception is thrown it gets this list from the web service by using the GeocoderRest class which has been pasted from here: https://mcmap.net/q/1449433/-problems-with-android-location-geocoder

Behemoth answered 3/6, 2014 at 14:40 Comment(2)
can you post your code for calling like for geocoder and for web service I also used similar technique but the json returned from geocoding web service was hugeKesler
I added the code in my edit.Behemoth
D
1

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

Simply no. In the majority of attempts there will always be a difference between these two geocoders. Because the android.location.Geocoder uses a Service internally, which you can't track down in the source code, you will never now where exactly the difference is, but asking Google. And I don't think they will give this info away.

Btw, the GeocoderRest class you use doesn't parse even the half of the info contained in the response. Usually the web service is much more reliable as the API in the SDK.

Deventer answered 3/6, 2014 at 15:31 Comment(1)
It doesn't parse all the information but the one I need is not available in some cases (e.g. the thoroughfare)... It seems that for France, the API gives more information than the web service. Thanks for your helpBehemoth

© 2022 - 2024 — McMap. All rights reserved.