Reputation: 1416
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.
Upvotes: 3
Views: 1058
Reputation: 895
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;
});
Upvotes: 2