2

I'm trying to find a plug-in on a leaflet in which the user will enter the address, and the HTML (aka the plug-in) will geocode the location and will return a latitude and longitude. So I have tried the Leaflet-Control Geocoder, but I cannot find the lat, long.

Does anyone have an example?

1 Answer 1

5

As per the Leaflet Control Geocoder plugin API documentation, you should:

  1. Attach an event on the "markgeocode" event of the L.Control.geocoder object.
  2. Read the event.geocode.center LatLng object that is passed to your event listener.
var geocoder = L.Control.geocoder()
.on('markgeocode', function(event) {
    var center = event.geocode.center;
    L.marker(center).addTo(map);
    map.setView(center, map.getZoom());
})
.addTo(map);

Demo: http://playground-leaflet.rhcloud.com/robi/1/edit?html,output

1
  • Alas, the link to the demo seems to be broken :-(
    – Mawg
    Commented Apr 5, 2019 at 6:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.