2015-07-19 100 views
0

在使用gmaps4rails不显示标记时遇到一些麻烦,请运行教程视频,仍然没有快乐。我已确认地理编码器工作正常。Gmaps4rails标记不显示

@shops控制器

def index 
@shops = Shop.all 
@hash = Gmaps4rails.build_markers(@shops) do |shop, marker| 
    marker.lat shop.latitude 
    marker.lng shop.longitude 
    marker.title shop.description 
end 

查看

<div style='width: 800px;'> 
    <div id="map" style='width: 800px; height: 400px;'></div> 
</div> 
    <script type="text/javascript"> 
     handler = Gmaps.build('Google'); 
     handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){ 
      markers = handler.addMarkers(<%=raw @hash.to_json %>); 
      handler.bounds.extendWith(markers); 
      handler.fitMapToBounds(); 
     }); 
    </script> 

回答

1

我不是100%肯定,但我认为marker.title可能是问题 - 你试过marker.infowindow

相关搜索:handler.addMarkers(#{raw(@hash)})

图片的标题说明: @hash是不是一个好名字的变量为什么不@markers? 此外,我会打电话的控制器.to_json - 我会离开,走出观点:只是在``末尾添加@hash.to_json`index``

我希望帮助!