Geocoding control standalone vanilla JS

This tutorial demonstrates how to search places usign the standalone MapTiler Geocoding Control, and shows both the JSON response from the Geocoding API and the selected list item.

This example doesn’t use a map. To use the control on a map, you can see code examples of how to use the Geocoding control with different map libraries and Javascript frameworks.

NPM module setup


npm install --save @maptiler/geocoding-control
import '@maptiler/geocoding-control/';

const geocodingControl = document.querySelector("maptiler-geocoder");
//Change the apikey attribute of the web component to load your API key from an environment variable or similar.
//const apiKey = "YOUR_MAPTILER_API_KEY_HERE";
//geocodingControl.apiKey = apiKey;

geocodingControl.addEventListener("response", (e) => {
  document.getElementById("results").innerHTML =
    e.detail ? JSON.stringify(e.detail, null, 2) : "";
});

geocodingControl.addEventListener("pick", (e) => {
  document.getElementById("results").innerHTML =
    e.detail ? JSON.stringify(e.detail, null, 2) : "";
});
Geocoding: Show place search results

Geocoding API

Tutorials

Search for places using the MapTiler Geocoding API.

How to search places by coordinates (reverse geocoding)

Reverse geocoding

Tutorials

Search places by coordinates using reverse geocoding.

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?