How to add Geocoding control to OpenLayers map

In this tutorial, you will learn how to add a geocoding control to a OpenLayers map. Geocoding control will enable map users to search places in the map.

Let’s start with a minimalistic HTML page that displays a fullscreen map. Replace YOUR_MAPTILER_API_KEY_HERE with your actual MapTiler API key.

Next, we will include the geocoder control script and styles. Add the following snippet to <head> element:

Finally, we will instantiate the geocoding control and add it to the map. Add the following snippet after the Leaflet map instantiation code:

You may then adjust the GeocodingControl CSS style:

Control can be additionally customized with various options which are documented on its project page.

Complete source code

Here just copy the sample source code and paste it into your HTML file (your key is included).
Or just copy the code below and replace YOUR_MAPTILER_API_KEY_HERE it with your actual MapTiler API key.

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 have a look at the  MapTiler Server API documentation for a comprehensive understanding of all the available options the geocoding API  provides.

 

On this page