2

I have a very weired problem with maps: When I search maps.google.com for 'rue du sapin, la marsa, tunisie' it finds it and works as expected.

Now I'm using the Api and I configured it this way

private static final String MAPS_REQUEST_URL = "http://maps.googleapis.com/maps/api/geocode/json?sensor=false&language=FR&components=country:TN&address=";

When I request this url with 'rue du sapin, la marsa, tunisie' it returns Rue du Sapin, Carthago, Tunisie

I tried to play with the region, language, country parameters but nothing makes it work: it seams Google is translating la marsa to cartahago (in its internal version: which is geographically somehow correct, since la marsa is near carthago.

But nobody in Tunisia will call La marsa: carthago it's non sense.

So the question is: why does the web client use the good terms and the Api not?


Checking with chrome developer, (on the network tab), I have this request that is executed. I don't know how to translate it to the other api's url

curl 'https://maps.google.com/maps/suggest?q=rue+du+sapin,+la+mars&cp=21&hl=en&gl=&v=2&clid=1&json=a&ll=34.768691,10.008545&spn=5.955003,16.907959&vpsrc=6&authuser=0&auth=526fd0392GzY4pXSd2dS4DPzdNUGxkJ-kLI&src=1,2&num=5&numps=2&callback=_xdc_._1fhndbld0j' -H ':host: maps.google.com' -H 'accept-encoding: gzip,deflate,sdch' -H 'accept-language: en-US,en;q=0.8,fr;q=0.6,cs;q=0.4,it;q=0.2,ar;q=0.2' -H 'user-agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36' -H ':path: /maps/suggest?q=rue+du+sapin,+la+mars&cp=21&hl=en&gl=&v=2&clid=1&json=a&ll=34.768691,10.008545&spn=5.955003,16.907959&vpsrc=6&authuser=0&auth=526fd0392GzY4pXSd2dS4DPzdNUGxkJ-kLI&src=1,2&num=5&numps=2&callback=_xdc_._1fhndbld0j' -H 'accept: */*' -H ':version: HTTP/1.1' -H 'referer: https://maps.google.com/' -H 'cookie: SS=(...)' -H ':scheme: https' -H 'x-chrome-variations: CIO2yQEIhrbJAQiltskBCKm2yQEIxLbJAQiehsoBCNeHygEIlorKAQ==' -H ':method: GET' --compressed

It seams this answer is related to my problem (even though from far away) Google Map APIs : UK specific results


Thanks in advance for every answer

Community
  • 1
  • 1
Zied Hamdi
  • 2,400
  • 1
  • 25
  • 40
  • When I search for ['rue du sapin, la marsa, tunisie' on Google Maps](https://maps.google.com/maps?q=rue+du+sapin,+la+marsa,+tunisie), it gives me "Rue du Sapin Carthago, Tunisia" – geocodezip Oct 27 '13 at 16:15
  • You're maybe not in Tunisia, that's why it answers you as the API answers me. That's an indicator of the problem (which I already knew: depending on where you are, you will have a different answer). The problem is that I want to have an answer as I have in my browser (they took care of it in the browser, but I can't find a way to get it from the API) – Zied Hamdi Oct 28 '13 at 11:50
  • @geocodezip please note it translated Tunisie to Tunisia when you typed: so ok, when you're outside Tunisia, you get the answer with Carthago. When you're inside (I don't know which parameter changes but) you get 'la Marsa' – Zied Hamdi Oct 28 '13 at 11:55
  • Have you tried to change lat and long values in url for Tunusia? – Kuzgun Nov 04 '13 at 15:19

2 Answers2

3

http://maps.googleapis.com/maps/api/geocode/json?sensor=true&language=EN&address=rue%20du%20sapin,%20la%20marsa (note sensor, language and nothing else apart from address) produces result set that contain all the data, "La Marsa Soukra" too.

One solution would be producing your own formatted_address from components you're receiving.

I hope you're having this problems with only one instance of location naming pair to filter ... yeah, I don't know what I'm talking about here ^^

~details right after the response

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "Rue du Sapin",
               "short_name" : "Rue du Sapin",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Carthago",
               "short_name" : "Carthago",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "La Marsa Soukra",
               "short_name" : "La Marsa Soukra",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "Tunis",
               "short_name" : "Tunis",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Tunisia",
               "short_name" : "TN",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Rue du Sapin, Carthago, Tunisia",
         "geometry" : {
            ...
         },
         "partial_match" : true,
         "types" : [ "route" ]
      }
   ],
   "status" : "OK"
}

My guess is that

When loaded from maps.googleapis.com, the current implementation of the Maps API v3 does not rely on the exchange of cookies with Google.

is kicking in here somehow ... or just plain preference is given to component locality over administrative_area_level_2 ... as match is only partial with confidence:0.51319576424371627?

maps.google.com/maps/suggest isn't even something anybody should use (API not even documented properly, deprecated v2 used maps.google.com/maps/geo) and use some of all that more or less private data google has.

I played around with cp parameter in

http://maps.google.com/maps/suggest?q=rue+du+sapin,+la+marsa&cp=21&hl=en

and 20 produced quite interesting results.

arkonautom
  • 958
  • 18
  • 29
  • Thanks arkonautom for your investigation, Now I don't know if I have the right to use maps.google.com/maps/suggest If it is subject to change without notification, I can't find a google documentation about it. Soooo Yeah! :-) As you said, it's not something to use in a serious project. I don't even know how many requests I can make on that without being fired :). Seems there's no real solution?... – Zied Hamdi Nov 05 '13 at 07:00
  • https://developers.google.com/places/documentation/autocomplete can be an alternative, but it's a lot less relevant in my use case, and it's not sure, there will not be the same issue – Zied Hamdi Nov 05 '13 at 07:26
  • Why do the Google Maps APIs Geocoders provide different locations than Google Maps? The API geocoder and Google Maps geocoder sometimes use different data sets (depending on the country). The API geocoder occasionally gets updated with new data, so you can expect to see results changing or improving over time. – arkonautom Nov 05 '13 at 08:01
  • https://developers.google.com/places/documentation/ seems like API that could indeed provide result you're looking for. It does requires API key though. – arkonautom Nov 05 '13 at 08:03
  • @Phpdna: I haven't said anything about your answer yet ;) I suggested parsing of metadata to get formatted address too, pointing out it won't be trivial to develop rules for large amount of data that OP intends to encounter. And giggled a little on idea to filter as it's plain silly in this case (checking ALL the data to be *local*?). Also link in answer to that question is exactly where I got that citation from. Keep calm and ... – arkonautom Nov 05 '13 at 08:55
1

You can replace Carthago with La Marsa. Or pretend Google Maps gives the right geocode. Most likely the geocode from Google Maps api is correct and you overthink it?! To improve your accuracy you can search the geocode for different names:Google Maps API: Geocode returns different co-ordinates then Google maps but most likely it uses different databases:Google Maps Web site and API : different results. There is also the name and the address: Google Map geocoder not as accurate as a Google maps. How to parse the geocode:how to parse a Google Maps geocoding result.

Community
  • 1
  • 1
Micromega
  • 12,486
  • 7
  • 35
  • 72
  • "la marsa" is only an example, there are surely others to discover – Zied Hamdi Nov 05 '13 at 07:03
  • No @Phpdna the response is clear. It just doesn't give the answer: you can see that http://maps.google.com/maps/suggest?q=rue+du+sapin,+la+marsa&cp=21&hl=en gives a good answer and the other doesn't. The downvote is beacuse you're suggesting a solution that works only for "La Marsa", which is obviously not a solution to my problem, otherwise, I wouldn't have used all this complexity of calling remote APIs: I would have written "La Marsa" in the code directly. Sorry, but this answer is definitely polluating the quality of the thread. I wouldn't have downvoted otherwise – Zied Hamdi Nov 05 '13 at 07:32