Skip to content

How to get a regular form field to autocomplete a geosearch with Leaflet’s Geosearch plugin?

I’m trying to get a regular form field used for searching for an address to autocomplete its values, as seen on this page, using Leaflet Geosearch plugin.

So far the documentation says it can be binded to a form. Jquery UI’s autocomplete looks like it can accomplish this, however i have not been able to wrap my head around how to do it.

I have successfully linked the form field to the geosearch provider, and it returns an array that can be seen in the browser console. I can algo get the autocomplete plugin to work, but with a local array, not the one produced by the geosearch plugin.

Here is an example of both plugins in action separately:

<!DOCTYPE html>
    <title>Leaflet tests</title>
<link rel="stylesheet" href="">
<script src=""></script>
<script src=""></script>
<link rel="stylesheet" href=""/>
<script src=""></script>
<style type="text/css"> #mapid { height: 500px; width: 500px}</style>

<link rel="stylesheet" href="" />
<script src=""></script>
 <div id="mapid"></div>


<div class="">
  <label for="search">geosearch field (check console): </label>
  <input id="search">

<div class="">
  <label for="search2">autocomplete field (apple or banana): </label>
  <input id="search2">

 <script type="text/javascript">
 //code for generating map below
 var mymap ='mapid').setView([51.505, -0.09], 13);
L.tileLayer('http://{s}{z}/{x}/{y}.png', {
  attribution: '&copy; <a href="">OpenStreetMap</a>',
  subdomains: ['a','b','c']

//code for search form below
const providerform = new GeoSearch.OpenStreetMapProvider();
const input = document.querySelector('input[id="search"]');
input.addEventListener('input', async (event) => {
  const results = await{ query: input.value });
  console.log(results[0]); // ยป [{}, {}, {}, ...]
let fruits = ['Apple', 'Banana']

        source: fruits,
        delay: 100,
        minLength: 1

I’d greatly appreciate any pointers in the right direction on how to get the autocomplete to work with the geosearch provider.



This should work, but I don’t know how to check at the moment because is currently not working.

  source(request, response) {
    const providerform = new GeoSearch.OpenStreetMapProvider({
      params: {
        limit: 5
    return{ query: request.term }).then(function (results) {
  delay: 100,
  minLength: 1
User contributions licensed under: CC BY-SA
4 People found this is helpful