Click to get Latitude and Longitude in google map using angular ng-map?

White Marcus picture White Marcus · Mar 15, 2016 · Viewed 10.1k times · Source

First of all I'm using Angular Google Map (ng-map). I want to get clicked location of google map's latitude and longitide.

My Code

<ng-map center="[{{latitude}}, {{longitude}}]">
   <marker position="[{{latitude}}, {{longitude}}]" title="how" animation="Animation.BOUNCE"></marker>
</ng-map>

Answer

daniel picture daniel · Mar 15, 2016

You could do that this way, and also could get the coordinates even on marker drag:

<ng-map on-click="getpos($event)">
    <marker ng-repeat="p in positions" 
      position="{{p}}" on-dragend="getpos($event)">
    </marker>
</ng-map>

and in your controller:

$scope.getpos = function(event) {
    console.log(event.latLng);
};

Fiddle: fiddle

Update: with initialize

Edit I would try

changing your js

app.run(function(editableOptions) {
    editableOptions.theme = 'bs3';
});

into

app.run(function(editableOptions, $rootScope) {
    editableOptions.theme = 'bs3';
    $rootScope.$on('mapInitialized', function(evt,map) {
        $rootScope.map = map;
        $rootScope.$apply();
    });
});