I am using the Google Maps API (https://maps.googleapis.com/maps/api/geocode/xml) to geocode places and addresses. However, the results seem inconsistent. The administrative_area_level_2 and locality OR the locality and sublocality_level_1 seem to overlap. But, depending on the address, the overlap is different. One of the things I need to do is determine the city. The documentation states that the locality is the equivalent of a city.
If I geocode "Noord-Holland, Nederland" which is a province I get:
- country:Nederland
- administrative_area_level_1: Noord-Holland
I can understand. All seems well...
If I geocode "Amsterdam, Noord-Holland, Nederland" I get the following result:
- country:Nederland
- administrative_area_level_1: Noord-Holland
- administrative_area_level_2:Amsterdam
- locality:Amsterdam
Here I start not understanding the result. Why is Amsterdam listed as an administrative_area_level_2 as well as a locality? But ok, Amsterdam is the locality, thus the city. Which is correct.
If I geocode "Anton de Komplein 150, 1102 CW Amsterdam, Noord-Holland, Nederland" I get the following results:
- country:Nederland
- administrative_area_level_1:Noord-Holland
- administrative_area_level_2:Amsterdam
- locality:Amsterdam-Zuidoost
- sublocality_level_1:Amsterdam-Zuidoost
Now I really don't understand.
- Here is Amsterdam-Zuidoost mentioned twice
- Why is the locality here "Amsterdam-Zuidoost"? It is not the city... I would have assumed that "Amsterdam" would be the locality and "Amsterdam-Zuidoost" the sublocality_level_1.
Can someone explain how i should interpretate the results?
2 Answers
Answers 1
I've had a look at your examples and I believe these are data issues that should be reported to Google.
Let's explain my findings:
The request for 'Amsterdam, Noord-Holland, Nederland'
https://maps.googleapis.com/maps/api/geocode/json?address=Amsterdam%2C%20Noord-Holland%2C%20Nederland&key=MY_API_KEY
returns the following address components for me
"address_components":[ { "long_name":"Amsterdam", "short_name":"Amsterdam", "types":[ "locality","political" ] }, { "long_name":"Government of Amsterdam", "short_name":"Government of Amsterdam", "types":[ "administrative_area_level_2","political" ] }, { "long_name":"North Holland", "short_name":"NH", "types":[ "administrative_area_level_1","political" ] }, { "long_name":"Netherlands", "short_name":"NL", "types":[ "country","political" ] } ]
Note that administrative_area_level_2 has a name 'Government of Amsterdam'. I understand you might be using the Dutch language to get results
https://maps.googleapis.com/maps/api/geocode/json?address=Amsterdam%2C%20Noord-Holland%2C%20Nederland&language=nl&key=MY_API_KEY
In this case I have:
{ "long_name":"Amsterdam", "short_name":"Amsterdam", "types":[ "locality","political" ] }, { "long_name":"Amsterdam", "short_name":"Amsterdam", "types":[ "administrative_area_level_2","political" ] }
So at this point it looks like the Dutch version is not translated correctly, we have 'Government of Amsterdam' in English and 'Amsterdam' in Dutch. This is a data issue. By the way you can see the administrative area level 2 here:
The second example is a bit more complicated.
https://maps.googleapis.com/maps/api/geocode/json?address=Anton%20de%20Komplein%20150%2C%201102%20CW%20Amsterdam%2C%20Noord-Holland%2C%20Nederland&key=MY_API_KEY
First of all you should be aware that for street address level searches you will get address components and formatted address in local language as described in the localization of street addresses article. So doesn't matter what language we specify English or Dutch we will see the Amsterdam as the administrative area level 2 and this is exactly the same data issue that we faced in the first example, it should be translated to 'Regering van Amsterdam' on Google side.
Referring to the locality component. It's really weird that Amsterdam-Zuidoost is defined as locality in Google database. I can see it as shown in the screenshot and it looks like a sublocality:
However if you check this feature in the Geocoder tool, it clearly states that this is a locality feature:
Note the pace ID is ChIJeYirmgYMxkcRRBetjCFkmyQ. I believe this also might be a data issue on Google side.
I would suggest sending a feedback to Google data team following the Google Maps help center:
https://support.google.com/maps/answer/3094045?hl=en&ref_topic=3093612
I hope my answer clarifies your doubts!
Answers 2
If a country like Netherlands had province's administrative_area_level_1
and administrative_area_level_2
would probably both be set. It's just a matter of how the country set itself up in my opinion.
The sublocality_level_1
is just a neighborhood or area inside the city, while the locality
is your current location. From all of the locations listed sublocality_level_1
is the most precise when it comes to locating you so then that is your locality
as well.
You could check if sublocality_level_1
is set and if it is then check the highest number in administrative_area_level_number
and use that for country otherwise use locality
.
0 comments:
Post a Comment