Skip to content

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

License

Notifications You must be signed in to change notification settings

maptiler/maptiler-geocoding-control

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

official page →

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

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

What?

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).

Why?

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 is also provided as React component and Svelte component and other libraries.

Install

Install the Geocoding control unsing npm:

⚠️ Warning! ⚠️

The current version of Geocoding Control is only compatible with Svelte v4, this will potentially cause peer dependency issues when installing with certain versions of npm in Svelte projects (eg if you're using Svelte v5), or if you intend to import the Svelte component directly.

If you are using a this library in a Svelte project you can npm install with --force or --legacy-peer-deps and use only the pre-compiled GeoLocatControl vanilla module, not the Svelte component.

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

Quick start

Use the component in your mapping application:

import * as maptilersdk from "@maptiler/sdk";
import { GeocodingControl } from "@maptiler/geocoding-control/maptilersdk";
import "@maptiler/sdk/dist/maptiler-sdk.css";
import "@maptiler/geocoding-control/style.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);

NOTE: Get your personal MapTiler API key in the MapTiler Cloud.

Installation and more usage examples

API Documentation

In addition to the details and examples provided in this README.md and our documentation, check out

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

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.