Different results between Android Geocoder and Google Geocoding web service

Posted by user3571822 on Stack Overflow See other posts from Stack Overflow or by user3571822
Published on 2014-06-03T14:40:51Z Indexed on 2014/06/03 15:25 UTC
Read the original article Hit count: 227

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 seem 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: http://stackoverflow.com/a/15117087/3571822

© Stack Overflow or respective owner

Related posts about android

Related posts about google-maps-android-api-2