2

I'm trying to find a plug-in on 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 try the Leaflet-Control Geocoder,but I am not able to the lat,long.

Does anyone have an example?

4

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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