Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get search value of leaflet map

      L.control.scale({ position: 'bottomleft' }).addTo(leafletMap);
    var searchcontroloption={position: 'topleft'};
     L.Control.geocoder(searchcontroloption)
    .on('markgeocode', function(e) {

             })
.addTo(leafletMap); 

I want to get search value, which user has typed in leaflet search box is there anyway to get it.

like image 948
gaurav singh Avatar asked Dec 28 '25 20:12

gaurav singh


1 Answers

Yes, there is a way to get what has been typed by the user. On latest version of L.Control.geocoder, the search <input> is located in a <div> which has 'leaflet-control-geocoder-form' class. With JQuery :

L.Control.geocoder(searchcontroloption).on('markgeocode', function(e) {
    var searchTxt = $('div.leaflet-control-geocoder-form input').val();
});

Without JQuery :

L.Control.geocoder(searchcontroloption).on('markgeocode', function(e) {
    var searchTxt = document.getElementsByClassName("leaflet-control-geocoder-form")[0]
                   .childNodes[0].value;
});
like image 81
Julien V Avatar answered Dec 30 '25 09:12

Julien V



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!