Reputation: 725
I use the parameter language=en when I'm connecting Google Maps API.
I use this code for detecting the city:
function locationHelper(array, key) {
var location = false;
$.each(array, function (i, object) {
if (object.types[0] == key) {
location = (object.long_name != "") ? object.long_name : object.short_name;
}
});
return location;
}
autocomplete.addListener('place_changed', function() {
var place = autocomplete.getPlace();
var city = locationHelper(place.address_components, 'locality');
console.log(city);
});
Why Google sends me Bucharest in Romanian variant (București) when I'm displaying data from autocomplete.getPlace()?
From documentation:
The default placeholder text is localized automatically. If you specify your own placeholder value, you must handle the localization of that value in your application. For information on how the Google Maps JavaScript API chooses the language to use, please read the documentation on localization.
I did it at the very beginning. As we can see, Google proposes us to select a language for variants. Only for variants, there is no word on the results. And I didn't find any solution yet.
Upvotes: 0
Views: 230
Reputation: 32148
The address formatting for details follows a policy described by Google in the following document:
https://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.
The same applies to Places API details, however, it looks like the autocomplete doesn't follow this guideline, but I believe Google currently is looking into this.
Upvotes: 1