Search code examples
ruby-on-railsgoogle-maps-api-3google-maps-markersdom-eventsgmaps4rails

Click on markers Google Maps API and change page using gmaps4rails


I'm using gmaps4rails and I have a good amount of markers, now when I click on a marker appears infowindow I need to click the marker and be redirected to another page.

Controller:

def index
@postos = Posto.all
@markers = Posto.all.to_gmaps4rails  

@json = Posto.all.to_gmaps4rails  do |posto, marker|
 marker.json "\"id\": #{posto.id}"
end  
  respond_to do |format|
   format.html # index.html.erb
   format.json { render json: @postos }
  end
end

Javascript:

 google.maps.event.addListener(marker_container.serviceObject, 'click', @openInfoWindow(currentMap, marker_container.infowindow, marker_container.serviceObject))

Solution

  • Well, you're almost ok but your js function seems out of subject, you should code something like:

     google.maps.event.addListener(marker_container.serviceObject, 'click', function() { your_code_to_change_page_depending_on_the_marker })