I'm trying to have multiple markers on one static map.
I am using geocoder gem (followed the railscast tutorial for this). Managed to get that working.
Now, I'm trying to loop all markers on one map it on the index page, but it shows up with each map separately.
This is the code on the index page:
<% @locations.each do |location| %>
<%= image_tag "http://maps.google.com/maps/api/staticmap?size=450x300&sensor=false&zoom=15&markers=#{location.latitude}%2C#{location.longitude}" %>
<% end %>
How do I loop through this so all the markers shows up on one map instead of map for each and every single longtitude/latitude?
Any advice would be appreciated and please let me know what further information I need to include.
It shows each map separately because you print image for every marker. What you want is, one URL and add &markers=#{location.latitude}%2C#{location.longitude}
to its end for each marker.
So your code should look like this:
<% my_url = "http://maps.google.com/maps/api/staticmap?size=450x300&sensor=false&zoom=15" %>
<% @locations.each do |location| %>
<% my_url += "&markers=#{location.latitude}%2C#{location.longitude}" %>
<% end %>
<%= image_tag my_url %>