Kasia Huma
Kasia Huma

Reputation: 11

Google Maps marker click listener

I need to add click event to Google Map markers, I'm using cordova in my app. Any way recommended in the documentation is not working... unless I make the marker draggable (then it works like gold) and I can't do that. I found that it was an issue a long, long time ago in 2011...

I think something had to be done with that since 2011. Do you have any idea?

Working piece of code below:

            var position = new google.maps.LatLng(coords.lat, coords.lng);
            var markerOptions = angular.extend({
                map: map,
                position: position,
                title: name,
                draggable: true

            }, DrawingOptions.marker);

            var googleMarker = new google.maps.Marker(markerOptions);

            var marker = {
                Id: id,
                Type: type,
                marker: googleMarker,
                circle: new google.maps.Circle(circleOptions),
            };

            marker.marker.addListener('click', function () {
                addInfoModal();

            });

I also tried to make a function adding listener, but it won't work. I was also thinking about not-so-graceful solution - making marker draggable, but actually preventing action while dragging, but this isn't working and it looks bad in code.

Have you heard of something helpful in this case?

Upvotes: 0

Views: 893

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133370

Seem your function is not right.

try without function simply adding the listener this way :

google.maps.event.addListener(googleMarker, 'click', function (event) {
                alert('click');
            }); 

Upvotes: 1

Related Questions