In this tutorial, you will learn how to add a geocoding control to a Leaflet 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
Finally, we will instantiate the geocoding control and add it to the map. Add the following snippet after the Leaflet map instantiation code:
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.