问题
I used google map api to get a street address of a house in Madrid, Spain. Then I got the following for place_administrative_area_level_1.
place_administrative_area_level_1_short: Comunidad de Madrid place_administrative_area_level_1_long: Comunidad de Madrid
Then I saved those details to database. Now I want to search the addresses I saved from Madrid. So from front end, again I search google place api by Madrid, Spain. Then google returns me the following for place_administrative_area_level_1.
place_administrative_area_level_1_short: Community of Madrid place_administrative_area_level_1_long: Community of Madrid
See the difference? Now I can't use this string to search my database as it has different value. In both cases, I am sending language=en. So why it is returning different values for this address field? The only difference is that, for the 1st one, I used like a street address of a house in Madrid. In second instance, I used like Madrid, Spain only. But in both cases, it should return the same value for place_administrative_area_level_1. Because of this, I can't search my database by a single value.
回答1:
This is because of localization policy applied by Geocoding API web service. You can read about it in the following post:
https://mapsplatform.googleblog.com/2014/11/localization-of-street-addresses-in.html
Street-level addresses returned by the Google Maps Geocoding API now favor the local language, while keeping the address understandable as much as possible for both a user who only reads the requested language as well as locals.
If the local language and user language both use the same alphabet, the Geocoding API will now return the local names for the streets and localities.
In your examples the first request searches street level address, so you get a Spanish name for address component administrative_area_level_1 Comunidad de Madrid
as mentioned above.
The second request is not a street level address, so the aforementioned policy is not applied and you get a name according to the language parameter which is English Community of Madrid
.
I believe you might be strongly interested in the following feature request:
Add place_id in each address_components
Once this feature request is implemented you will be able to compare place ids instead of the names in address components.
I hope this addresses your doubt.
来源:https://stackoverflow.com/questions/54459688/place-administrative-area-level-1-return-different-values-for-same-area