gmaps4rails显示带有地图控件的空白地图

时间:2011-05-05 00:54:23

标签: ruby-on-rails ruby ruby-on-rails-3 google-maps gmaps4rails

尝试让gmaps4rails在rails 3项目中运行。我根据演示设置了所有设置,但我的视图仅显示地图应该在灰色背景上的地图控件。尝试用铬和野生动物园。有什么想法吗?

在模型中:

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东西:

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

在@venues收集的场地数据: 姓名,地址,城市,州,邮编,纬度,经度
Altena Restaurant,3346 Mission St,San Francisco,CA,94110,-122.421695,37.742956
LA Morena Latinoamericana,3391 Mission St,San Francisco,CA,94110,-122.421735,37.742668
Costa Del Sol II,3385 Mission St,San Francisco,CA,94110,-122.42178,37.742578
El Amigo Bar,3355 Mission St,San Francisco,CA,94110,-122.421575,37.742862
三十三俱乐部,3300 Mission St,San Francisco,CA,94110,-122.421485,37.743123

1 个答案:

答案 0 :(得分: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]