Skip to content

About

The Javascript & TypeScript Map Control component for MapTiler Geocoding service! Easy to be integrated into any JavaScript mapping application.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

85 stars

Watchers

9 watching

Forks

Latest commit

Β 

History

332 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Company Logo

MapTiler Search and Geocoding control for MapTiler SDK, MapLibre GL JS, Leaflet and OpenLayers

The Javascript & TypeScript Map Control component for MapTiler Geocoding service! Easy to be integrated into any JavaScript mapping application.

The MapTiler Geocoding control implements a powerful search box in your maps or online forms, enabling your application users to find any place on Earth down to individual addresses. Use the search box control with MapTiler SDK JS (or other map libraries like Leaflet, MapLibre GL JS, OpenLayers).


πŸ“– Documentation Β  πŸ“¦ NPM Package Β  🌐 Website Β  πŸ”‘ Get API Key



Table of Contents

Demo Screenshot
See live interactive demo


πŸ“¦ Installation

Install the Geocoding control unsing npm, together with your map library (MapTiler SDK as an example):

npm install --save @maptiler/geocoding-control @maptiler/sdk

πŸš€ Basic Usage

Use the component in your mapping application (MapTiler SDK as an example):

import * as maptilersdk from "@maptiler/sdk";
import { GeocodingControl } from "@maptiler/geocoding-control/maptilersdk";
import "@maptiler/sdk/dist/maptiler-sdk.css";

maptilersdk.config.apiKey = "YOUR_MAPTILER_API_KEY_HERE";

const map = new maptilersdk.Map({
  container: "map", // id of HTML container element
});

const gc = new GeocodingControl();

map.addControl(gc);

Without a bundler

With MapTiler SDK JS, you can load both libraries from MapTiler's CDN as ES modules. The import map tells the browser where to load @maptiler/sdk from, so your page and the Geocoding control share the same SDK:

<link rel="stylesheet" href="https://cdn.maptiler.com/maptiler-sdk-js/v5.0.0/maptiler-sdk.css" />

<script type="importmap">
  { "imports": { "@maptiler/sdk": "https://cdn.maptiler.com/maptiler-sdk-js/v5.0.0/maptiler-sdk.min.mjs" } }
</script>

<script type="module">
  import * as maptilersdk from "@maptiler/sdk";
  import { GeocodingControl } from "https://cdn.maptiler.com/maptiler-geocoding-control/v4.0.0/maptilersdk.cdn.mjs";

  maptilersdk.config.apiKey = "YOUR_MAPTILER_API_KEY_HERE";

  const map = new maptilersdk.Map({ container: "map" });

  map.addControl(new GeocodingControl());
</script>

Prefer classic <script> tags? Use the UMD builds: load the SDK's maptiler-sdk.umd.min.js first, then the control's maptilersdk.umd.js, which provides the global maptilerGeocoder.GeocodingControl.


πŸ’‘ Related Examples

Check out the full list of MapTiler geocoding examples


πŸ“˜ API Reference

For detailed guides, API reference, and advanced examples, visit our comprehensive documentation:

API documentation

Geocoding service API documentation

UMD global variables


Migration Guide

Upgrading from v3 to v4

Version 4 supports the new major versions of the map libraries. The GeocodingControl API and its options stay the same, except for the marker options with MapTiler SDK JS.

Map library Geocoding control v3 Geocoding control v4
MapTiler SDK JS 3 – 4 5
MapLibre GL JS 5 6
Leaflet 1.5 – 1.9 2
OpenLayers 9.1 – 10 9.1 – 10 (no change)

Upgrade your map library first (see its own migration guide), then the Geocoding control. If you need to stay on an older version of your map library, keep using v3 of the Geocoding control.

MapTiler SDK JS

  • The control's markers are now the MapTiler SDK's own Marker, which has different options than the MapLibre GL JS one. If you pass marker options in marker or showResultMarkers, use the MapTiler SDK Marker options, e.g. outerColor instead of color and scale as [x, y] instead of a number. The control's default markers look the same as before.
  • Functions in marker and showResultMarkers get the MapTiler SDK Map and return the MapTiler SDK Marker. Add the marker to the map with map.addMarker(marker), because MapTiler SDK JS 5 deprecates marker.addTo(map).

MapLibre GL JS

  • MapLibre GL JS 6 is published only as an ES module and has no default export. Replace import maplibregl from "maplibre-gl" with import * as maplibregl from "maplibre-gl" or with named imports such as import { Map, Marker } from "maplibre-gl".

  • The control's UMD build maplibregl.umd.js was removed, because MapLibre GL JS 6 no longer provides the global maplibregl it needs. Use the ES module build with a bundler instead, or switch to MapTiler SDK JS, which still has a UMD build (see below).

  • MapLibre GL JS 6 loads its web worker from a file next to its own module. Once a bundler moves MapLibre into your app's bundle, the map fails with Worker failed to load. Check that the worker URL is correct. With Vite, let Vite bundle the worker and pass its URL to MapLibre before creating the map:

    import { setWorkerUrl } from "maplibre-gl";
    import workerUrl from "maplibre-gl/dist/maplibre-gl-worker.mjs?worker&url";
    
    setWorkerUrl(workerUrl);

    With other bundlers, serve maplibre-gl-worker.mjs together with maplibre-gl-shared.mjs (which it imports) from node_modules/maplibre-gl/dist/ and pass the worker's URL to setWorkerUrl().

If upgrading to MapLibre GL JS 6 is difficult, or you need a UMD build for classic <script> tags, consider switching to MapTiler SDK JS and the control's maptilersdk build. The SDK is built on MapLibre GL JS, is available on MapTiler's CDN as both a UMD and an ES module build (see Without a bundler), and loads its web worker on its own, so none of the setup above is needed.

Leaflet

  • Leaflet 2 removed the factory functions such as L.map() or L.tileLayer(). Create objects with new instead, e.g. new Map(...) and new TileLayer(...). The Geocoding control is added the same way as before: map.addControl(new GeocodingControl({ ... })).
  • When using the control's UMD build leaflet.umd.js with classic <script> tags, load Leaflet's leaflet-global.js (it defines the global L) before it.

πŸ’¬ Support

  • πŸ“š Documentation - Comprehensive guides and API reference
  • βœ‰οΈ Contact us - Get in touch or submit a request
  • 🐦 Twitter/X - Follow us for updates



🀝 Contributing

We love contributions from the community! Whether it's bug reports, feature requests, or pull requests, all contributions are welcome:

  • Fork the repository and create your branch fromΒ main
  • If you've added code, add tests that cover your changes
  • Ensure your code follows our style guidelines
  • Give your pull request a clear, descriptive summary
  • Open a Pull Request with a comprehensive description
  • Read the CONTRIBUTING file

Development

Building

npm install && npm run build

You will find compilation result in the dist directory.

Running in dev mode

npm install && VITE_API_KEY=YOUR_MAPTILER_API_KEY_HERE npm run dev

Alternatively, you can provide your API key via key URL param.

POI icons and bundlers

POI icons are served from CDN per default. If there is an requirement to serve them from a different location and the control is used in the application which is built with Web Application bundler (like Webpack or Vite) then it is necessary to do some extra configuration. Icons are bundled in the library and you can find them in node_modules/@maptiler/geocoding-control/icons. Configure your bundler and/or provide iconsBaseUrl option for the icons to be properly resolved. You can also copy icons from that directory to your public directory.


πŸ“„ License

This project is licensed under the BSD 3-Clause License – see theΒ LICENSEΒ file for details.


πŸ™ Acknowledgements

The Geocoding control uses the MapTiler Geocoding API. You can use the API directly from your web or backend applications or use the API Client JS library.

With this control, users of mapping application can:

  • Find any place on Earth (States, Cities, Streets, Addresses, POIs, ...) down to the address level
  • Find and identify objects or place names using a coordinate pair or a single mouse click (reverse geocoding)
  • Restrict the search area to a specific country, bounding box, or proximity
  • Highlight searched results on the map (marker or full geometry)
  • Autocomplete words while typing
  • and much more. Check out the Geocoding Control API reference to see all the options.

The component can be used as an ES module or UMD module with or without bundler.

Geocoding control itself is provided as a Web component which can be used with React, Svelte, and any other modern frontend library, or without any library at all.


Get Your API Key FREE
Start building with 100,000 free map loads per month ・ No credit card required.


πŸ’œ Made with love by the MapTiler team

Website β€’ Documentation β€’ GitHub

About

The Javascript & TypeScript Map Control component for MapTiler Geocoding service! Easy to be integrated into any JavaScript mapping application.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

85 stars

Watchers

9 watching

Forks

Releases

Packages

Used by

Contributors

Languages