google maps marker link

I'm trying to have my markers as links to each page associated with them. So far I have managed to put a link in the info box, but I want to bypass this and just have the marker as the link. I'm using gmaps4rails gem.

Controller

@hash = Gmaps4rails.build_markers(@soiltemps) do |soiltemps, marker|
      location_link = view_context.link_to soiltemps.site, soiltemp_path(soiltemps)
      marker.lat soiltemps.latitude
      marker.lng soiltemps.longitude
      marker.picture({"url" => "/logo.png",
                      "width" =>  36,
                      "height" => 36})
      marker.infowindow "<h4><u>#{location_link}</u></h4> "
    end


ANSWERS:


You can do:

@hash = Gmaps4rails.build_markers(@soiltemps) do |soiltemps, marker|
  marker.lat soiltemps.latitude
  marker.lng soiltemps.longitude
  marker.picture({"url" => "/logo.png",
                  "width" =>  36,
                  "height" => 36})
  marker.json({ link: soiltemp_url(soiltemps) })
end

and add the listeners in your js:

markers_json = <%=raw @hash.to_json %>;
handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
  markers = handler.addMarkers(markers_json);
  handler.bounds.extendWith(markers);

  for (var i = 0; i < markers.length; i++) {
    link = markers_json[i].link;
    google.maps.event.addListener(markers[i].getServiceObject(), 'click', function(){
      window.open(link);
    })
  }

  handler.fitMapToBounds();
});

For url to same window with back - You can do:

@hash = Gmaps4rails.build_markers(@soiltemps) do |soiltemps, marker|
  marker.lat soiltemps.latitude
  marker.lng soiltemps.longitude
  marker.picture({"url" => "/logo.png",
                  "width" =>  36,
                  "height" => 36})
  marker.json({ link: soiltemp_url(soiltemps) })
end

and add the listeners in your js:

markers

_json = <%=raw @hash.to_json %>;
handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
  markers = handler.addMarkers(markers_json);
  handler.bounds.extendWith(markers);

  for (var i = 0; i < markers.length; i++) {
    link = markers_json[i].link;
    google.maps.event.addListener(markers[i].getServiceObject(), 'click', function(){
      window.location.assign(link);
    })
  }

  handler.fitMapToBounds();
});

More on window location assign (link)



 MORE:


 ? Disable zoomOnclick when initializing Google maps with "Gmaps4rails"
 ? Gmaps4rails map showing broken controls
 ? Gmaps4rails - how to set clustering grid size
 ? Gmaps4rails - how to set clustering grid size
 ? Gmaps4rails - how to set clustering grid size
 ? Prevent marker clustering with gmaps4rails
 ? How to change the zoom where the markers are clustered in gmaps4rails
 ? Gmaps4rails: What's the proper way to enable clustering after adding markers via AJAX?
 ? gmaps4rails: Uncaught ReferenceError: Gmaps is not defined
 ? gmaps4rails v2 fitMapToBounds()