gpt4 book ai didi

javascript - 尝试加载谷歌地图时发生rails 5未捕获的引用错误

转载 作者:行者123 更新时间:2023-12-03 04:26:45 28 4
gpt4 key购买 nike

当我尝试使用 google-maps-for-rails gem 加载动态谷歌地图时,我的 Chrome 控制台中出现以下错误。

Uncaught ReferenceError: handler is not defined

enter image description here

My locations controller index action (where map is to be loaded):

  def index
@locations = Location.all

@hash = Gmaps4rails.build_markers(@locations) do |location, marker|
marker.lat location.latitude
marker.lng location.longitude
end
end

The various scripts required:

<script src="https://maps.googleapis.com/maps/api/js?key=MY_KEY_HERE" async defer></script>
<script src="//cdn.rawgit.com/mahnunchik/markerclustererplus/master/dist/markerclusterer.min.js"></script>
<script>
markers = handler.addMarkers(<%=raw @hash.to_json %>);
</script>

The Map Div:

<div style='width: 800px;'>
<div id="map" style='width: 800px; height: 400px;'></div>
</div>

不知道我哪里出了问题,任何帮助将不胜感激!

干杯。

最佳答案

您错过了handler变量:

handler = Gmaps.build('Google');

所以代码应该是:

<script src="https://maps.googleapis.com/maps/api/js?key=MY_KEY_HERE" async defer></script>
<script src="//cdn.rawgit.com/mahnunchik/markerclustererplus/master/dist/markerclusterer.min.js"></script>
<script>
handler = Gmaps.build('Google');
markers = handler.addMarkers(<%=raw @hash.to_json %>);
</script>

关于javascript - 尝试加载谷歌地图时发生rails 5未捕获的引用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43673436/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com