1

I want to retrieve the longitude and latitude position of my click mouse event, but i can't, it gives me Undefined. Any one can help me please ?
I'm using AngularJS and I found that we can do

google.maps.event.addListener(map, 'click', function(event) {
    console.log(event.latLng);
});

But I can't do so in my controller it gives me an error, or maybe i don't know how to use that!!

here is my code :

$scope.map = {
        center: {
            latitude: 36,
            longitude: -80 
        },
        events: {
            "click": function (event) {
                console.log(event.latLng);
              }
         }
     }

and I tried that too but it gives me (Nan,Nan)

  $scope.map = {
            center: {
                latitude: 36,
                longitude: -80 
            },
            events: {
                "click": function (event) {
                    var pos = new google.maps.LatLng(event.latLng, event.latLng);
                    console.log("position: " + pos);
                  }
             }
         }

1 Answer 1

1

I could solve it like that

  events: {
        tilesloaded: function (map, eventName, originalEventArgs) {
            //map is trueley ready then this callback is hit
        },
        click: function (mapModel, eventName, originalEventArgs) {
            var e = originalEventArgs[0];
            var lat = e.latLng.lat(),lon = e.latLng.lng();
            console.log("lat long: "lat, lon);
            $scope.$apply();
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.