Using Geocode Earth with Leaflet

Adding an autocomplete search box to your Leaflet powered map is easy with Geocode Earth.

Here’s a complete HTML snippet that creates a full screen Leaflet map with search box:

    <title>Geocode Earth Leaflet autocomplete demo</title>
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <link rel="stylesheet" href=""
    <script src=""
    <link rel="stylesheet" href="">
    <script src=""></script>
      html, body, #map {
        width: 100%; height: 100%;
        margin: 0; padding: 0; border: 0;
  <div id="map"></div>

    // create basic Leaflet map
    var map ='map', {
      center:[42.35, -71.08],
      zoom: 3,
      scrollWheelZoom: false,
      zoomControl: false

    // add zoom control in topright corner
    L.control.zoom({ position:'topright' }).addTo(map);

    // Set Geocoder options
    var geocodingOptions = {
      url: '',
      expanded: true,
      attribution: '<a href="">Geocode Earth</a>, <a href="">OpenStreetMap</a> and <a href="">others</a>'

    // Replace with your Geocode Earth API key
    L.control.geocoder('<YOUR API KEY>', geocodingOptions).addTo(map);

    // Add a raster tile layer
    L.tileLayer('https://stamen-tiles-{s}{z}/{x}/{y}.png', {
      attribution: 'Tiles by <a href="">Stamen Design</a>',
      maxZoom: 17,
      minZoom: 1

Be sure to replace <YOUR API KEY> with your Geocode Earth API key.

See it in action #

For a working demo of what you’ll get, see our autocomplete demo.

Customizing #

The geocoder plugin can be customized in many ways, see the documentation on GitHub for more details.

Leaflet itself can also be extensively customized. See the Leaflet API Reference for everything Leaflet can do.