Geocoding with MapLibre GL JS

In this tutorial, you will learn how to add a geocoding control to the Maplibre GL JS map. Geocoding control will enable map users to search places on the map.

NPM module setup


npm install --save maplibre-gl @maptiler/geocoding-control
import maplibregl from "maplibre-gl";
import { GeocodingControl } from "@maptiler/geocoding-control/maplibregl";
import "maplibre-gl/dist/maplibre-gl.css";

const apiKey = "YOUR_MAPTILER_API_KEY_HERE";

const map = new maplibregl.Map({
  container: "map", // id of HTML container element
  style: `https://api.maptiler.com/maps/streets-v4/style.json?key=${apiKey}`
});

const gc = new GeocodingControl({ apiKey, maplibregl });

map.addControl(gc);

Geocoding on-prem with MapTiler Server

You can utilize the geocoding capabilities within your on-prem installation of MapTiler Server. This feature allows you to search for addresses and locations without an internet connection. Please take a look at the MapTiler Server API documentation for a comprehensive understanding of all the available options the Geocoding API provides.

Was this helpful?