Repository navigation
Replies: 1 comment
|
This comes from the Maps JavaScript API's default language. If you don't set one, Google picks it per visitor from the browser's language headers, so a visitor whose browser prefers French gets "Bruxelles" and one on English gets "Brussels". Brussels is officially bilingual, so both are valid names, which is why it looks random. To force one language for everything (map labels and service responses), set it on the <APIProvider apiKey={API_KEY} language="en">
{/* ... */}
</APIProvider>
If you only need certain requests in a fixed language (e.g. keep the map in the visitor's language but always store English city names), the services take a per-request override: // Geocoder
const geocoder = new google.maps.Geocoder();
const { results } = await geocoder.geocode({ address: 'Bruxelles', language: 'en' });
// Places autocomplete (new API)
const { suggestions } =
await google.maps.places.AutocompleteSuggestion.fetchAutocompleteSuggestions({
input: 'Brux',
language: 'en',
});
// Place details: fetchFields() has no language option, so set it on the Place
const place = new google.maps.places.Place({ id: placeId, requestedLanguage: 'en' });
await place.fetchFields({ fields: ['displayName', 'addressComponents'] });References: |
Uh oh!
There was an error while loading. Please reload this page.
I've been getting some mixed results with fetching certain locations, for example in Belgium we have "Brussels", which is the English name of the city, but sometimes the result will be "Bruxelles" (the french name), is there an option to force a certain language?
All reactions