首页 文章

无法渲染gmaps4rails Map

提问于
浏览
1

好吧,我一直在尝试使用gmaps4rails渲染谷歌 Map 几个小时,我无法弄清楚,所以我希望在这里得到一些想法 . 我觉得我很接近 .

这就是我所做的:

  • 在github上完成设置步骤:https://github.com/apneadiving/Google-Maps-for-Rails

  • 注意到我的视图中的gmaps4rails方法调用在标记中添加了一些JS代码,所以我在对Gmaps.load_map()的JS调用上放了一个断点 . 在这个方法中,我在Gmaps.map.initialize()上设置了一个断点 . 此时,我的页面中会显示一个空白的div区域(要渲染 Map 的位置),但是当我单步执行此行时,该区域将被隐藏(特别是在初始化期间的 Map 创建期间,隐藏发生的位置:返回new google.maps.Map(document.getElementById(this.map_options.id),mergedOptions)) . 之后的下一行是调用 Map 标记,提供了一个lat / lng对象数组,如下所示:Gmaps.map.markers = [{"lat":90.2765777,"lng":-37.7498712}],所以基本上它's leading me to think that my gmaps model object is fine (I also put a breakpoint in my controller for kicks and double checked that the call for my mappable object' s to_gmaps4rails()返回适当的数据) .

  • 还注意到我的firebug网络标签中有几次调用google maps api(调用maps.gstatic.com,mt0.googleapi.com和maps.googleapi.com) .

  • 确保将gmaps4rails css文件下载到我的浏览器会话中(我正在获取gmaps4rails.css) .

  • 尝试使用google api密钥在我的视图上添加脚本标记,但后来发现我并不需要最新版本,如下所述:Google Maps API-Key in gmaps4rails

  • 在SO上搜索了类似的问题并发现这些无济于事:gmaps4rails not showing mapgmaps4rails is not displaying the map

我认为我遗漏了一些非常简单的东西,因为数据似乎已经到位以便渲染 Map . 有任何想法吗?

1 回答

  • 1

    事实证明,我正在我自己的 Map div中包装gmaps4rails的map_container div,这就是扔掉了gmaps4rails . 我假设gmaps4rails的JS逻辑插入并依赖于它自己的div #map . 所以基本上不要将你的gmaps4rails调用包装在id =“map”的div中 .

    在我的haml中,我有这个:

    #map
      = gmaps4rails(@mapData)
    

    当我需要这个时:

    = gmaps4rails(@mapData)
    

    要么:

    #foo
      = gmaps4rails(@mapData)
    

相关问题