How to specify the geocoding control language(s) response text and prioritization

Indicate the language(s) utilized for the response text and the prioritization of query results in geocoding control. Include the language options within the control constructor. For a complete list of geocoding control options, please refer to the Geocoding control’s reference documentation. In the given example, we initialize the control to incorporate French and English languages.

NPM module setup


npm install --save @maptiler/sdk @maptiler/geocoding-control
import { Map, MapStyle, config } from '@maptiler/sdk';
import '@maptiler/sdk/dist/maptiler-sdk.css';
import { GeocodingControl } from '@maptiler/geocoding-control/maptilersdk';

config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';
const map = new Map({
  container: 'map', // container id
  style: MapStyle.STREETS,
  center: [-72.745, 46.081], // starting position [lng, lat]
  zoom: 6, // starting zoom
});
//set geocoding control language. Example Canada, Quebec province that is primarily Francophone
const gc = new GeocodingControl({
  language: ['fr', 'en']
});
map.addControl(gc, 'top-right');
document.getElementById('buttons').addEventListener('click', function (event) {
  // Retrieve language based on button id
  gc.setOptions({ 
    language: event.target.id,
    placeholder: setPlaceHolder(event.target.id)
  });
});
function setPlaceHolder(language) {
  switch (language) {
    case 'en':
      return 'Search';
      break;
    case 'fr':
      return 'Recherche';
      break;
    case 'de':
      return 'Suchen';
      break;
    case 'ja':
      return '検索';
      break;
    case 'es':
      return 'Buscar';
      break;  
    default:
      return 'Search';
      break;
  }
}

Learn more

Check the MapTiler Geocoding control API reference for all search options. For example specifying the language of the results, etc.

Do you want to see how the geocoder component is made? Check the MapTiler Geocoding control repository. You can also use it as inspiration to create your component.

Discover the process of integrating the geocoding control feature into your React (Geocoding React component repository) or Svelte (Geocoding Svelte component) applications. Additionally, you have the option to use the VanillaJS version to customize it for any of your applications.

Are you currently using a different map library? No worries! Learn how to incorporate the geocoding control functionality with Leaflet (Leaflet Geocoding control), OpenLayers (OpenLayers Geocoding control), or MapLibre GL JS (MapLibre GL JS Geocoding control).

Geocoding: Show place search results

Geocoding API

Tutorials

Search for places using the MapTiler Geocoding API.

Geocoding limit results by area (bounding box)

Geocoding limit results by area

Examples

Limit geocoding search results to a specific bounding box area.

Geocoding search results closer to specific point

Geocoding search results by proximity to a specific point

Examples

Rank geocoding search results higher based on proximity.

Geocoding search results to specified country(ies)

Geocoding search results to specified country(ies)

Examples

Limit geocoding control search results to specific countries.

Was this helpful?