3

I'm trying to remotely troubleshoot an app for a client. The app creates its Geocoder and looks up addresses like this:

Geocoder gc = new Geocoder(context, Locale.getDefault());
List<Address> addresses = gc.getFromLocationName(nextWaypoint, 5);

The waypoint is a Canadian street address. The client reports that the app can geocode addresses on some devices, but fails to geocode the same addresses on other devices. The devices on which it fails are Android 4.0.3 devices from Israel.

My hunch is that the Israeli devices are expecting an address in whatever format they use in Israel, and not even recognizing the Canadian addresses as addresses. Does that seem likely, or even possible?

Edit: I wrote a test app that suggests my original idea was wrong. The client gave me a sample address (this one in the US) and I wrote a test app that creates two Geocoders with explicit locales: one using Locale.US, the other new Locale("iw", "IL"). Both are able to geocode the sample address on my 4.4 device.

Based on the code and the error message the client is seeing, getFromLocationName(...) must be returning zero results on the Israeli 4.0.3 devices. It returns results for the same address on other devices.

Is Geocoder known to be flaky in 4.0.3?

Edit 2: It might be related to issue 38009. But the client reported seeing a toast that they would only see if getFromLocationName(...) returned an empty list, not if it threw an exception.

Kevin Krumwiede
  • 9,868
  • 4
  • 34
  • 82
  • What is the failure when you use `getFromLocationName()`? – Elliott Feb 10 '15 at 00:46
  • Based on looking at the code and the message the client is seeing, `getFromLocationName(...)` must be returning zero results. I can't reproduce the failure on any device I have access to. – Kevin Krumwiede Feb 10 '15 at 01:13
  • Well then I am imagining there is no *failure* but probably your search results are zero. _Returns a list of Address objects. Returns null or empty list if no matches were found or there is no backend service available._ – Elliott Feb 10 '15 at 01:15
  • Being that this isn't a crash. I think the problem is that you are trying to get the Canadian address to conform to the Israel locale. I am betting that is why you are getting zero results. Are all your wavepoints in Canadian? I will respond below with my suggestion for resolution. – Elliott Feb 10 '15 at 01:21
  • @Elliott I made an edit. – Kevin Krumwiede Feb 10 '15 at 01:32
  • 1
    I have seen people suggest that this could be due to the fact that the area is under conflict and that google will not give back anything for that. I don't buy it but I have no idea why you would get zero results. They should implement the API so you get a reason back with the results. – Elliott Feb 10 '15 at 15:01

2 Answers2

2

Unfortunately I don't have a great answer but from what I gather this is what I think you should do.

  1. I would double check that you are not seeing a crash or exception thrown from the Geocode api on your users devices.
  2. If the case is still that you are just getting zero results I would make a google bug ticket Android Bug Tracker and see what they say. I have seen talk of people saying that in areas where conflict is going on that they will not give service but I have not seen anything directly from google so I would get clarity on that.

To be honest I think these are really your only two options as if there are no crashes and the APIs don't explicitly tell us why they would give us zero results. If you create a ticket please share back here, I am interested to see what Google's response would be.

Elliott
  • 539
  • 4
  • 14
  • You're probably right. I'll write a small test app and send it to the client to make sure there's no ambiguity arising from their bug report or my reading of the spaghetti code. If the test app demonstrates the problem, I'll post a bug report and link it here. – Kevin Krumwiede Feb 14 '15 at 20:48
0

I am not sure if this is the same issue that you have, but I'll tell mine(and my partial solution)...

I am searching for customized places on Google maps, first time the map activity is active, the near locations are automatic shown on map (perfectly), but I noticed that when I was searching for de exactly same location (using EditText input), the customized places weren't shown on map.

I found out that Geocode results were not the same when I was converting THE PLACE ADDRESS (from the EditText input) and the customized places addresses from the GeoCode (from my database input).

The reason was that the Geocode instance (Geocode(context) or even Geocode(context, locale)) were returning some of the the results in the searched country Locale [the Geocode(context, locale) instance seems not to be working].

Exemple: (My default device locale is PT-BR) 1 - If I was searching for Milan (Italy), the geocode results from the EditText input(Milan), were in PT-BR (Milão) and the Geocode result from the CUSTOMIZED object located in Milan were coming in IT (Milano).

2 - If I was searching for London(UK), the geocode results from the EditText were in PT-BR (Londres - Reino Unido) [EVEN IF MY INPUT WAS IN ENGLISH] and the Geocode result from the CUSTOMIZED object located in Milan were coming in EN (London - United Kingdom).

This way I could not match the results (I believe the Geocode returns should be in Locale.Default language).

My solution was: Getting the result address from default Geocoder, comparing its language to the default lang [result.getCountryCode]. If different set a new Geocoder instance using the first result language [new Geocoder(context, Locale.forLanguageTag(result.getCountryCode())]. and keep this new result.

[ I am using the same instance of Geocoder(context, locale) for getting the results from the place I want(from EditText) and getting the results of my custom places(from database), this way, no matter what language I insert on EditText, I always get the correct result ]

Geocoder geocoder = new Geocoder(parentContext);
Address placeResult = null;
 try {
     List<Address> addresses = geocoder.getFromLocationName(address, 1);
     if (addresses.size() > 0) {
     placeResult = addresses.get(0);
     Log.d(TAG, String.format(">>> CONVERTED PLACE COUNTRY >>> %s <<<", placeResult.getCountryCode()));

   if(!placeResult.getCountryCode().equalsIgnoreCase(Locale.getDefault().getCountry())) {
   Log.d(TAG, String.format(">>> CHANGING CONVERTED PLACE COUNTRY >>> From: %s To: %s <<<", Locale.getDefault().getCountry(), placeResult.getCountryCode()));
   geocoder = new Geocoder(parentContext, Locale.forLanguageTag(placeResult.getCountryCode()));
   addresses = geocoder.getFromLocationName(address, 1);
   }
   placeResult = addresses.get(0);
} catch (IOException e) {
  e.printStackTrace();
  return;
}

finding my custom places:

try {
   studioGeoAddress = geocoder.getFromLocation(studioLatitude, studioLongitude, 1).get(0);

  Log.d(TAG, String.format(">>> CONVERTED STUDIO GEO ADDRESS >>> %s <<<", studioGeoAddress.toString()));
  Log.d(TAG, String.format(">>> CONVERTED STUDIO LOCALE >>> %s <<<", studioGeoAddress.getLocale()));

  Log.d(TAG, String.format(">>> STUDIO PROFILE >>> %s <<<", studioProfile.getDisplayName()));
  Log.d(TAG, String.format(">>> STUDIO ADDRESS HAS COUNTRY >>> %s | %s <<<", studioGeoAddress.getCountryName(), placeResult.getCountryName()));
  Log.d(TAG, String.format(">>> STUDIO ADDRESS HAS ADMIN >>>   %s | %s <<<", studioGeoAddress.getAdminArea(), placeResult.getAdminArea()));
  Log.d(TAG, String.format(">>> STUDIO ADDRESS HAS SUB-ADMIN >>>   %s | %s <<<", studioGeoAddress.getSubAdminArea(), placeResult.getSubAdminArea()));
  Log.d(TAG, String.format(">>> STUDIO ADDRESS HAS LOCALITY >>> %s | %s <<<", studioGeoAddress.getLocality(), placeResult.getLocality()));
  Log.d(TAG, String.format(">>> STUDIO ADDRESS HAS SUB-LOCALITY >>> %s | %s <<<", studioGeoAddress.getSubLocality(), placeResult.getSubLocality()));


if (placeResult.getSubAdminArea() != null) {
  if (studioGeoAddress.getSubAdminArea() != null) {
   Log.d(TAG, String.format(">>> STUDIO SUB-ADMIN >>> %s | %s <<<", studioGeoAddress.getSubAdminArea(), placeResult.getSubAdminArea()));
   if(studioGeoAddress.getSubAdminArea().equalsIgnoreCase(placeResult.getSubAdminArea())) {
   Log.d(TAG, String.format(">>> STUDIO ADDED TO LIST >>> %s  [MATCH] <<<", studioProfile.getDisplayName()));
   STUDIOS_LIST.add(studioProfile);
   }
 }
} catch (IOException e) {
 e.printStackTrace();
}

That was my solution, maybe there is something easier or less complicated, but it works for now.

Ps. Sorry about my english..

Erick Cabral
  • 141
  • 2
  • 7