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.
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;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With