For AI agents: a documentation index is available at /llms.txt. Markdown versions of all pages are available by appending .md to any URL.
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 * as maplibregl from "maplibre-gl";
import { setWorkerUrl } from "maplibre-gl";
import workerUrl from "maplibre-gl/dist/maplibre-gl-worker.mjs?worker&url";
import { GeocodingControl } from "@maptiler/geocoding-control/maplibregl";
import "maplibre-gl/dist/maplibre-gl.css";
setWorkerUrl(workerUrl);
const apiKey = "YOUR_MAPTILER_API_KEY";
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);
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="robots" content="noindex" />
<title>Geocoding in MapLibre GL JS</title>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<div id="map"></div>
<script type="module" src="./main.js"></script>
</body>
</html>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
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.