-1

I applied fix as described here to richmarker.js

Once i use

my_rich_marker.addListener('click', function(event) {
    console.log(event); //undefined
}

What i need is to get event.latLng of richmarker within onclick function like it works with regular marker.

Community
  • 1
  • 1
MrDX7
  • 1

2 Answers2

0

The event argument passed into the "click" event for RichMarker is the argument from the browser's native click event, which doesn't have a .latLng property.

from the RichMarker source:

var that = this;
google.maps.event.addDomListener(this.markerContent_, 'click', function(e) {
  google.maps.event.trigger(that, 'click', e);
});

You have two options:

  1. modify the RichMarker library to add the latLng property to the returned event.

  2. calculate the associated latLng from the properties available in the browser's native click event.

  3. set the latLng property of the returned event to this.getPosition() (based off of Dr.Molle's answer):

    google.maps.event.addListener(my_rich_marker, 'click', function(event) {
      event.latLng = this.getPosition();
      console.log(event.latLng.toUrlValue()); 
    }
    
geocodezip
  • 158,664
  • 13
  • 220
  • 245
0

When you really want it like it works with regular marker:

When you click on a regular marker the latLng-property of the event is equal to the position of the marker.

So all you would have to do is to retrieve the position of the RichMarker:

google.maps.event.addListener(my_rich_marker,'click',function(e){
  console.log(this.getPosition());
});
Dr.Molle
  • 116,463
  • 16
  • 195
  • 201