angular-google-maps icon indicating copy to clipboard operation
angular-google-maps copied to clipboard

Get Lat Long from click event on map

Open dgavigan opened this issue 12 years ago • 1 comments

Might just be a misunderstanding, but I'm trying to get the coords from the point a user clicks on. Looks simple enough with the reggie gmap API v3 with something like:

google.maps.event.addListener(map, 'click', function(event) {
    var myLatLng = event.latLng;
    var lat = myLatLng.lat();
    var lng = myLatLng.lng();
})

I've wired up a click function to the directive as so:

        $scope.mapEvents = {"click":function(event){
            console.log(event)
            }
        }

However, the returned event doesn't appear to have a lat() and lng() method. Ive been digging through the properties of the object and its quite a beast. Any ideas?

dgavigan avatar May 01 '14 20:05 dgavigan

(always think of something AFTER I post an issue)

I was able to get the lat long by checking any other returned data, which indeed it does. The click event will return an array as a third argument, containing lat lng at the first index.

Hope this helps anyone who runs into the same question.

If there is another or preferred way, do tell!

dgavigan avatar May 01 '14 20:05 dgavigan