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://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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With