Ruby on Rails - gmaps4rails 显示带有地图控件的空白地图



试图让gmaps4rails在rails 3项目中工作。我已经根据演示设置了所有内容,但我的视图仅在地图应该所在的灰色背景上显示地图控件。在chrome和safari中尝试过。有什么想法吗?

在模型中:

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

在应用程序.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 餐厅, 3346 Mission St, 旧金山, 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
Thirty Three Hundred Club, 3300 Mission St, San Francisco, CA, 94110, -122.421485, 37.743123

该死的,来回看了 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]

相关内容

  • 没有找到相关文章

最新更新