I have an application that has a location model geocoded by the address entered by the user, right now Im showing the google map given the address geocoded in the location instance, now what I want to do is show the foursquare venues with its icons in the map that shows the location instance, how could I achieve this, Im already getting the nearby venues in a list, how can I show them in the map with its icon.
This is the show view and controller in which I want to see the map with the location instance plus the foursquare venues nearby...
def show
@location = Location.find(params[:id])
@json = Location.where('slug = ?', params[:id]).to_gmaps4rails
end
The view:
<% provide(:title, @location.name) %>
<% if [email protected]? %>
<%= content_tag(:div, "Location currently deactivated!", class: "alert") %>
<% end %>
<div class="row-fluid">
<aside class="span4" >
<section>
<h1>
<%= @location.name %>
</h1>
<%= gmaps({
"map_options" => { "auto_zoom" => false, "zoom" => 17 },
"markers" => { "data" => @json }
}) %>
</section>
</aside>
</div>
Thank you for your help!
Well, hard to guess how your venues look like but I could give you what I suspect could work.
Hypothesis:
to_gmaps4rails
spits JSON out
venues have at least latitude, longitude. Maybe picture.
Your goal: add json from venues to json from locations.
One track:
locations_array_of_hashes = JSON.parse(@json)
venues_array_of_hashes = #do what is necessary to build an array containing hashes like { lat: , lng: , marker_picture: }
global_array_of_hashes = locations_array_of_hashes.concat venues_array_of_hashes
@global_json = global_array_of_hashes.to_json