我正在尝试使用gmaps4rails。当我添加记录时,客户端表正在填充纬度和经度。但是,地图没有显示任何内容。
在浏览器控制台中,我收到错误:第二行“未定义Gmaps”:
<script type="text/javascript">
Gmaps.map = new Gmaps4RailsGoogle();
Gmaps.load_map = function() {
我的javascript gmaps4rails文件夹包含咖啡文件和我的application.js中的这些行:
//= require gmaps4rails/gmaps4rails.base
//= require gmaps4rails/gmaps4rails.bing
//= require gmaps4rails/gmaps4rails.googlemaps
//= require gmaps4rails/gmaps4rails.mapquest
//= require gmaps4rails/gmaps4rails.openlayers
我的观看代码是:
<ul id="markers_list">
<%= gmaps("markers" => {"data" => @json, "options" => {"list_container" => "markers_list" } }) %>
</ul>
我的模特有:
acts_as_gmappable
def gmaps4rails_address
"#{address1}, #{city}, #{state}, #{zipcode}"
end
def gmaps4rails_infowindow
"#{client_name}, #{address1}, #{city}, #{state}, #{zipcode}"
end
def gmaps4rails_sidebar
"<span>#{client_name}</span>"
end
有什么想法吗?
谢谢!
更新: 我一直在看浏览器控制台。
这是在视图页面中,我正在尝试显示Google地图:
<footer>
<script src="//maps.google.com/maps/api/js?v=3.8&sensor=false&client=&key=&libraries=geometry&language=&hl=&region=" type="text/javascript"></script>
<script src="http://maps.gstatic.com/cat_js/intl/en_us/mapfiles/api-3/8/12/%7Bmain,geometry%7D.js" type="text/javascript"></script>
<script type="text/javascript">
Gmaps.map = new Gmaps4RailsGoogle();
Gmaps.load_map = function() {
Gmaps.map.initialize();
Gmaps.map.markers = [{"description":"Salt Lake County Headquarters, 2001 South State Street, Salt Lake City, UT, 84114","sidebar":"<span>Salt Lake County Headquarters</span>","lat":40.7267176,"lng":-111.8881423},
...(more data points right here)
Gmaps.oldOnload = window.onload;
window.onload = function() { Gmaps.triggerOldOnload(); Gmaps.loadMaps(); };
</footer>
我很确定在前两个脚本src =之后,还应该有:
<script src="/javascripts/gmaps4rails/gmaps4rails.base.js?1355589475" type="text/javascript"></script>
<script src="/javascripts/gmaps4rails/gmaps4rails.googlemaps.js?1355589475" type="text/javascript"></script>
但是,这些最终会进一步向下。在我看来,在执行gmaps之前没有加载2个脚本。所以,我得到的gmaps没有定义错误。
有什么想法吗? 谢谢!
答案 0 :(得分:1)
那么,为什么要将地图渲染成markers_list?
<!-- render your map here -->
<%= gmaps("markers" => {"data" => @json, "options" => {"list_container" => "markers_list" } }) %>
<!-- and here you render the markers_list -->
<ul id="markers_list"></ul>
你是否真的包含{/ 1}}
答案 1 :(得分:0)
终于明白了。以下代码行在我的布局页脚中:
<%= stylesheet_link_tag "application", :media => "all" %>
将其移至标题,Gmaps4rails开始工作。