0

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.

cnjap
  • 380
  • 3
  • 6
  • 24

2 Answers2

2

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)
});

lyjackal
  • 3,984
  • 1
  • 12
  • 25
  • I tried but still not working. It returns error in console. TypeError: Cannot read property 'lat' of undefined – cnjap Apr 09 '15 at 19:20
  • Ah! figured it out. After inserting a `console.log(arguments)` in the event, it looks like the leaflet event with the geo info is in the second argument. – lyjackal Apr 10 '15 at 00:50
0
.controller('MapController', function (leafletData) {
                  leafletData.getMap().then(function(map) {
                       map.on('click', function(e) {
                         console.log("Latitude : " + e.latlng.lat + " Longitude :  "+ e.latlng.lng);
                    });
              });