简体   繁体   中英

Google maps API V3 response language is wrong for city name

I am trying to implement the google maps API. All is working well except for the response which is coming back from google. The response translates the city name to my locale language (NL) but leaves the country in the desired language (EN).

Both the map and the autocomplete are displaying EN names of cities. However when clicking on a suggestion the input get's changed in just a fraction of a second to the NL variant (again leaving the country name in EN)

Here is the script tag that I am currently using:

<script type="text/javascript" src='http://maps.google.com/maps/api/js?libraries=places&language=en&key=MYKEY'></script>

The current output I get:

addressLine1:"14 Bisschopsstraat"
addressLine2:""
city:"Brussel"
country:"Belgium"
country_short:"BE"
postalCode:"1000"
stateOrProvince:"Brussel"
streetName:"Bisschopsstraat"
streetNumber:"14"

I have tried:

  • Adding a region=GB to the script tag src query but that just influences the search area priorities
  • Reading all the documentation (there is not that much on how to change the language of the response though)

Examples of what is wrong with the response:

Brussel should be Brussels

Antwerpen should be Antwerp

自动完成示例

If you use geocoding or places service this seems to be the intended behavior.

Please have a look at this post: http://googlegeodevelopers.blogspot.com.es/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. For example, searching for an address in Brazil with user language set to English now returns “Avenida Paulista” rather than “Paulista Avenue”.

The workaround I can think about is the following:

  1. You get a place ID from autocomplete element https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Bisschopsstraat%2014%2C%20Brussels%2C%20Belgium&key=YOUR_API_KEY This returns place ID EiVCaXNzY2hvcHNzdHJhYXQgMTQsIEJydXNzZWxzLCBCZWxnaXVt
  2. You execute place details request to get latitude and longitude https://maps.googleapis.com/maps/api/place/details/json?placeid=EiVCaXNzY2hvcHNzdHJhYXQgMTQsIEJydXNzZWxzLCBCZWxnaXVt&key=YOUR_API_KEY This will return 50.8503548,4.351704499999999
  3. Execute reverse geocoding for latitude,longitude specifying result type as locality and language as English https://maps.googleapis.com/maps/api/geocode/json?latlng=50.8503548%2C4.351704499999999&language=en&result_type=locality&key=YOUR_API_KEY And here you have "formatted_address":"Brussels, Belgium"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM