Search code examples
angularjsleafletangular-leaflet-directive

How to get geo coordinates on clicked location of map using Angular-Leaflet-directive?


How to get geo coordinates on clicked location using leaflet? I try something like ..

  $scope.$on('leafletDirectiveMap.geojsonClick', function (e) {
             alert("Lat, Lon : " + e.latlng.lat + ", " + e.latlng.lng)
    });

but it didn't work.


Solution

  • angular-leaflet wraps up the regular leaflet event in the second argument. Alos, you just want 'click' like normal leaflet but with the 'leafletDirectiveMap' prefix.

    jsfiddle


     $scope.$on('leafletDirectiveMap.click', function (e, wrap) {
             alert("Lat, Lon : " + wrap.leafletEvent.latlng.lat + ", " + wrap.leafletEvent.latlng.lng)
    });