0

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 !@location.active? %>
  <%= 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!

maumercado
  • 1,453
  • 4
  • 23
  • 47

2 Answers2

0

the foursquare2 gem could be usefull to you.

m_x
  • 12,357
  • 7
  • 46
  • 60
  • Hello, actually Im using quimby and Im already getting a venues array connecting to foursquare and stuff, the problem that Im having is adding those venues markers to a gmaps4rails created map with the marker for an instance of a location... – maumercado Nov 10 '12 at 15:38
  • just merge the two arrays. if you need distinct markers, see http://stackoverflow.com/questions/5666173/google-maps-js-api-v3-simple-multiple-marker-example-with-custom-markers – m_x Nov 10 '12 at 16:13
  • it does not work, because the location class I have in my app has act_as_gmappable, but the foursquare objects are not mappable via gmaps4rails – maumercado Nov 10 '12 at 19:15
0

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
apneadiving
  • 114,565
  • 26
  • 219
  • 213