2011-05-05 83 views
0

試圖讓gmaps4rails在rails 3項目中工作。我根據演示安排了一切設置,但我的視圖僅在地圖應該顯示的灰色背景上顯示地圖控件。試用鉻和safari。有什麼想法嗎?gmaps4rails顯示空白地圖與地圖控件

在模型:

acts_as_gmappable :process_geocoding => false 

def gmaps4rails_address 
    "#{address}, #{city}, #{state} #{zip}" 
end 

在控制器:

@venues = Venue.limit(5) 
@venue_map_data = @venues.to_gmaps4rails 

在視圖:

<%= gmaps4rails(@venue_map_data) %> 

在application.html.erb佈局:

<!DOCTYPE html> 
<html> 
<head> 
    <title>MapTest</title> 
    <%= stylesheet_link_tag :all %> 
    <%= javascript_include_tag :defaults %> 
    <%= csrf_meta_tag %> 
    <%= yield :head %> 
</head> 
<body> 
    <%= yield %> 
    <%= yield :scripts %> 
</body> 
</html> 

的Javascript的東西:聚集在@venues

<script src="/javascripts/gmaps4rails.js" type="text/javascript"></script> 
<script type="text/javascript" src='http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclusterer/1.0/src/markerclusterer_compiled.js'></script> 
<script type="text/javascript" charset="utf-8"> 
function gmaps4rails_init() { 
    Gmaps4Rails.map_options.auto_adjust = true; 
    Gmaps4Rails.initialize(); 
    Gmaps4Rails.markers = [{"longitude": "37.742956", "latitude": "-122.421695"}, 
      {"longitude": "37.742668", "latitude": "-122.421735"}, 
      {"longitude": "37.742578", "latitude": "-122.42178"}, 
      {"longitude": "37.742862", "latitude": "-122.421575"}, 
      {"longitude": "37.743123", "latitude": "-122.421485"}]; 
    Gmaps4Rails.create_markers(); 
    if(typeof gmaps4rails_callback == 'function') { gmaps4rails_callback(); } 
} 

function gmaps4rails_loadScript() { 
    var script = document.createElement("script"); 
    script.type = "text/javascript"; 
    script.src = "http://maps.google.com/maps/api/js?sensor=false&libraries=geometry&callback=gmaps4rails_init"; 
    document.body.appendChild(script); 
} 

window.onload = gmaps4rails_loadScript; 

</script> 

地點數據: 名稱,地址,城市,州,郵編,經度,緯度
阿爾特納餐廳,3346團街,舊金山,CA,94110, -122.421695,37.742956
LA莫雷納拉丁美洲,3391團街,舊金山,CA,94110,-122.421735,37.742668
科斯塔勒II,3385團街,舊金山,CA,94110,-122.42178,37.742578
薩爾瓦多Amigo Bar,3355 Mission St,San Francisco,CA,94110,-122.421575,37.742862
三十三百年俱樂部,3300團街,舊金山,CA,94110,-122.421485,37.743123

+0

你有產量:在您的頁腳腳本?你能粘貼創建的js嗎? – apneadiving 2011-05-05 07:43:55

+0

我確實有收益:腳註中的腳本和yield:頭部在頭部。 – jmcopeland 2011-05-05 16:07:54

回答

3

媽的,剛拿到的20項分鐘找來回後...

沒事做的寶石:看你的座標:

Gmaps4Rails.markers = [{"longitude": "37.742956", "latitude": "-122.421695"}, 
     {"longitude": "37.742668", "latitude": "-122.421735"}, 
     {"longitude": "37.742578", "latitude": "-122.42178"}, 
     {"longitude": "37.742862", "latitude": "-122.421575"}, 
     {"longitude": "37.743123", "latitude": "-122.421485"}] 

你把你的緯度放在經度表中,反之亦然。

經度= [-180,180]

緯度= [-90,90]

+0

您是正確的先生,這是我使用的單獨的地理編碼庫中的一個錯誤,交換了緯度/經度。謝謝!順便說一句,很棒的寶石。 – jmcopeland 2011-05-06 02:36:12