[GIS] Geocoding single address with Leaflet

geocodingleaflet

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?

Best Answer

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