Reputation: 1289
This is what I have for displaying the map with markers
<%= javascript_tag do%>
var handler = Gmaps.build('Google');
handler.buildMap({ internal: {id: 'multi_markers'}}, function(){
var markers = handler.addMarkers(<%=raw @hash.to_json %>);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
});
<%end%>
<% content_for :scripts do %>
<script type="text/javascript" charset="utf-8">
Gmaps.map.callback = function() {
if (Gmaps.map.markers.length == 1) {
var marker = Gmaps.map.markers[0];
var infowindow = marker.infowindow;
infowindow.open(Gmaps.map.map, marker);
}
}
</script>
<% end %>
Not exactly sure how should I be trying to have the infoWindows/markers open default on page load.
Thanks
Upvotes: 0
Views: 778
Reputation: 115541
The solution consists in triggering the click
event on markers, then adjust map.
_.each(markers, function(marker){
google.maps.event.trigger(marker.getServiceObject(), 'click');
});
And remove the part with Gmaps.map.callback
, its for 1.x
Upvotes: 4