Search code examples
angularjsleafletmarkerangular-leaflet-directive

Get marker location in Angular Leaflet Direction


I'm using Angular Leaflet Directive. In the example, say here form the docs (http://tombatossals.github.io/angular-leaflet-directive/#!/examples/dragging-markers), we have a marker that is draggable. Changing the location of the draggable Madrid marker is possible by clicking up and down on the lat/lng input.

Is there a way for the reverse to happen? That is, when the marker is dragged, the location is updated in those input values?

Alternately, is there a way to access a specific marker and retrieve its coordinates with the directive?


Solution

  • you should take a look at this link: http://tombatossals.github.io/angular-leaflet-directive/examples/0500-markers-simple-example.html

    Specifically at those lines:

    $scope.$on("leafletDirectiveMarker.dragend", function(event, args){
        $scope.position.lat = args.model.lat;
        $scope.position.lng = args.model.lng;
    });
    

    There is also a marker ID, if you have more than one marker on the map.

    Also, you should know that when you drag marker, lat/lng properties of that marker update themselves, so you can use simple $watch, too.