1
votes

The Mapbox API supports geocoding requests fine, but I always get the results in English. I'd like to be able to get results in a specific language.

For the Mapbox.js API, it's possible to display the map in a different language (by changing style), but I can't find a way to translate geocoding requests correctly.

For example, if I pass in the city 'Gent', I would expect to see that it's in province Oost-Vlaanderen and country Belgiƫ. However, I get 'Gent, Oost-Vlanderen, Belgium'. This would be done using a request like: https://api.mapbox.com/geocoding/v5/mapbox.places/Gent.json?country=be&access_token=MYACCESSTOKEN

Is there a way to get the correctly translated result? Perhaps using a setting or extra parameter?

2

2 Answers

2
votes

The localized names that I see in Streets-v8 (and likely in mapbox.places) are name_en, name_es, name_fr, name_ru, & name_zh.

This looks like you'll need to file a feature request with Mapbox, at least you may be able to have support for name_fr.

I like to use the Mapbox Command Line Interface to see the responses from the Mapbox querys. This particular query gives a response of "place_name": "Gent, Oost-Vlanderen, Belgium",

mapbox-cli>   mapbox geocoding 'Gent' --country be 

I also tried Ghent in the query, but still received English

The town shows as Ghent in the Mapbox language switch example.

1
votes

Looks like a solution has been implemented!

Just pass in a language field on the initialization object like so:

var geocoder = new MapboxGeocoder({ language: 'es' }); //change lang to spanish

Got it from these docs: https://github.com/mapbox/mapbox-gl-geocoder/blob/master/API.md#mapboxgeocoder