2012-11-10 24 views
0

我有一個應用程序,它具有由用戶輸入的地址進行地理編碼的位置模型,現在我顯示給定地址的谷歌地圖,在地點實例中進行地理編碼,現在我想要do是在地圖上顯示foursquare地點及其地圖中顯示位置實例的圖標,我如何實現這一點,我已經在列表中獲取附近的場地,我如何使用它的圖標在地圖中顯示它們。添加foursquare場地以及實例gmaps4rails的位置

這是展示視圖和控制器中,我想看到的位置,例如加上附近的四方場地地圖...

def show 
    @location = Location.find(params[:id]) 
    @json = Location.where('slug = ?', params[:id]).to_gmaps4rails 
    end 

的觀點:

<% 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> 

謝謝您的幫助!

回答

0

那麼,很難猜測你的場地是怎樣的,但我可以給你我想要的東西。

假設:

  • to_gmaps4rails吐出JSON出

  • 場館至少有緯度,經度。也許圖片。

你的目標:從場館添加JSON從位置到JSON。

賽道:

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 
0

foursquare2 gem可能對你有用。

+0

你好,實際上進出口使用昆比和Im已經接到了場地陣列連接到Foursquare和東西,即有被添加這些場館標記來創建地圖標記一個gmaps4rails IM的問題對於一個位置的實例... – maumercado

+0

只是合併這兩個數組。如果您需要不同的標記,請參閱http://stackoverflow.com/questions/5666173/google-maps-js-api-v3-simple-multiple-marker-example-with-custom-markers –

+0

它不起作用,因爲位置類我在我的應用程序中有act_as_gmappable,但foursquare對象不能通過gmaps4rails映射 – maumercado