Android Geocoder - different results when called from different geographical locations - android

I have the following code in my Android program
List<Address> addressList = geoCoder.getFromLocation(37.790551,-122.433931, 1);
if (!addressList.isEmpty()) {
address = addressList.get(0);
String number = address.getSubThoroughfare();
String streetName = address.getThoroughfare();
.....
}
This is a request to essentially get a street name (hence the 1) from a latitude and longitude in San Francisco.
When I execute this program on a phone in Europe (specifically Ireland) number is returned as 2250-2290 and streetname is returned as Fillmore St.
When I get a friend to run the same code on his phone in California number is null and streetname is still Fillmore st.
I've seen other SO questions allude to region settings but is this possible that the geographical location can affect the query in the Android API?
The Javascript Geocoding API mentions region bias. I wonder is it possible to do something similar in the Android API. I did try creating the Geocoder as
Geocoder geoCoder = new Geocoder(getApplicationContext(), Locale.US);
but this does not re-recreate the California based result.

From getting people to run identical code on different continents it seems that location is indeed a factor.
The Javascript geocoding allows you to specify a region though

Are the phones running different versions of android? Also, another thing to keep in mind is that "The Geocoder class requires a backend service that is not included in the core android framework." So, if the two phones are calling upon different backend services to query for the Geocoder, that may explain the output you are seeing.
I think with Android 1.5, they included a Google API backend service implementation for Geocoder. I don't know if newer versions of Android and the Google API made changes to the Geocoder implementation that may be giving you different results or it's coming from some other backend service.

Related

Mapbox - Reverse Geocoding - multiple language response

I'm using Mapbox to Reverse geocode a latitude, longitude location and wanted the city name(Place name) response with multiple languages.
The documentation says,
'If more than one language tag is supplied, text in all requested languages will be returned'
But I'm getting the response only in the first language specified.
MapboxGeocoding.builder()
.accessToken("xyz..."),
.query(Point.fromLngLat(-123.1207, 49.2827))
.languages("zh-CN,ru")
.geocodingTypes(GeocodingCriteria.TYPE_PLACE)
.mode(GeocodingCriteria.MODE_PLACES)
.build();
This returns the place name in Chinese and not Russian.
Documentation : https://www.mapbox.com/android-docs/api/mapbox-java/libjava-services/4.0.0/index.html
Verison used: 'com.mapbox.mapboxsdk:mapbox-sdk-services:4.1.0' and also 'com.mapbox.mapboxsdk:mapbox-sdk-services:4.1.0-SNAPSHOT'
I have contacted the Mapbox team. Apparently, this is a bug in their Mobile SDK but their API works fine. Have reported this here. https://github.com/mapbox/mapbox-java/issues/446

Android mapquest geocoder country-setting

Since I own an app key for mapquest (community edition), all geocoding requests end up in US only. Before I entered the app key geocoding european locations was possible.
I couldn't find a method to set a default country. Even initializing the geocoder object with a Locale didn't work.
Any suggestions?
Currently the mapquest Android API doesn't support single line international geocoding.
This is the reply I got from mapquest:
I checked at our Android API is still using our v1 geocoder which does
not support single line international geocoding. My support suggested
you use our geocoding web service for the geocoding first:
http://developer.mapquest.com/web/products/dev-services/geocoding-ws
Again just make sure the request says “v2”.

How to make an autocomplete address search text box that retrieves the same result as Android Maps?

I've created an autocomplete address search text box. My problem is that I just can't make it work fine:
Addresses are out of the bounding box usually, whatever I do - this didn't help.
Finds addresses that doesn't contain the typed text.
Finds less addresses, than max but it doesn't contain the good result.
The result list is totally irrelevant sometimes.
I need to type almost the whole address to get the correct result.
Source:
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = null;
try {
if (Geocoder.isPresent()) {
// Bounding box: Hungary
addresses = geocoder.getFromLocationName(text, 5, 46.13, 21.96, 48.89, 16.69);
}
} catch (IOException e) {
Log.v(tag, "Geocoding error: " + e.getMessage());
e.printStackTrace();
}
My aim is to make an address search text box which gets the same result as in Android Maps seach text box - except the previously typed/favourite addresses and etc., which is an other story.
The Google Places Autocomplete API may be of help. As far as I know you must license it for use in commercial apps. If your app is for free then you should be fine.
EDIT about inaccurate Geocoder results:
I haven't yet played around much with Geocoder. But what I can tell you so far is the following:
You need to take into consideration that on some devices all methods return null (check Geocoder.isPresent() to be sure) because Geocoder relies on some underlying implementation that can be missing on some devices.
And it is also possible that these results come from an other Geocoder engine / service than Google Places.
On top of that the query results are never perfect. You rarely get the exact address of the current location either because the location is off or because the Geocoder data is not accurate enough (or simply outdated).
If you really need an accurate address you should give the user both a list of best candidate options and some means for manually editing the address.
If you need more accurate results based on the location name you could take a look at available online services that perform better for your needs. One example is geonames.org. If their database is good enough for you, then you need to get or implement some Java API for interfacing with the service of your choice and use that instead Geocoder.

Geoder.getFromLocationName doesn't give the same results as maps.google.nl

First of all: Geocoder is present and works fine on my android application. It gives results for the examples from the android documentation:
"Dalvik, Iceland", an address such as "1600 Amphitheatre Parkway, Mountain View, CA", an airport code such as "SFO", etc..
But when I search a restaurant or something like that in my own country, the Netherlands, geocoder won't find anything. But if I type the same query string into maps.google.nl it gives me directly the restaurant I was looking for.
I already have tried to restrict the geocoder within two long/lat points, but that doesn't make any difference. So it seems that I can find anything in de US easily, but finding a location of a restaurant in the Netherlands doesn't work
The Google Geocoding API (which I think is what your Android app is querying) will only return geographical features, not business listings. Those are available on Google Maps because that's an application and uses more search backends than the Geocoding API.
Appending the country name won't help, what you'll get in your Android app (using the geocoder) is the same you will get from the Google Maps API v3 Geocoder Tool. It does include some POIs, but not all business listings (restaurants, hotels, etc.).
Some time ago I had a similar problem with UK adresses, I believe it's because the web app has more context than just the portion of the map you're looking at (like which countries are in view).
If I recall correctly, I solved it by appending ", UK" or ", GB" (or ", United Kingdom" / ", Great Britain") to all queries, so in your case try appending ", Netherlands".

google maps API and geocoder.getFromLocationName

I want to search for GPS locations for with Google Maps. I have already registered with Google Maps API, and got the key. I can successfully pinpoint my current location on a map. The next part is to search for items around the current GPS location.
Approach 1: I tried using Android's geocoder.getFromLocationName("UPS",5) but I am not getting anything.
Approach 2: hit Google https://maps.googleapis.cm/maps/apo/place/search but it needs a client id. To get a client id I have to create a premier account. Do I have to do all this?
Any suggestion how to use maps to search location for Android?
"GPS" is the place you're looking up? Not a city or street name? I think that's the problem here.
Maybe look at:
How can I find the latitude and longitude from address?
You will want to use a better "address" other than UPS to find locations using Geocoder. Do you realize how many UPS locations will be found. getFromLocationName() is best used with detailed location info and a locale directive so it limits its searching to the Locale you specify. Also, you will frequently get IOExceptions in the emulator. Lastly using SDK 2.3 and above will not work with Geocoder.
Try something like this:
Geocoder geocoder = new Geocoder(this, Locale.US);
String staddress = "Georgia Tech, Atlanta, GA";
try{
List<Address> loc = geocoder.getFromLocationName(staddress, 5);
}
catch(IOException e) {
Log.e("IOException", e.getMessage());
Toast.makeText(this, "IOException: " + e.getMessage(),20).show();
Notice how the locale is set to US when I new up my Geocoder. Also notice the try catch around the call to geocoder. That will catch any IO Exceptions and allow you ot handle them as I did using a Toast message and some other flow control statements that are out of sight

Categories

Resources