Search code examples
google-mapsgmaps4railsgmaps4rails2

gmaps4rails V2 unable to retrieve markers position


I'm using gmaps4rails V2 and and I'm not able to retrieve the markers position.

I have my array of Markers:

markers = handler.addMarkers(<%=raw @hash.to_json %>);

I want to iterate over it and delete the marker out of my map bounds

$.each markers, ->       
  pos = this.getPosition
  if !bounds.contains pos  
    handler.removeMarker this

This is my console output:

Uncaught TypeError: Object #<Marker> has no method 'getPosition' 

Am I missing something?


Solution

  • Markers created by the gem are proxy on which you can create some methods.

    To access the google object do:

     this.getServiceObject()
    

    Then:

     this.getServiceObject().getPosition() // mind the parenthesis!