Jquery Gmaps4rails在阵列中循环
我有一个包含30多个位置的阵列,我想在地图上显示。但是,我还没有找到一个源代码来演示如何迭代数组以使标记出现在地图上,而是选择严格硬编码地图lat/long值 例如,这是我目前拥有的代码,但它返回错误:Jquery Gmaps4rails在阵列中循环,jquery,ruby-on-rails,coffeescript,gmaps4rails,Jquery,Ruby On Rails,Coffeescript,Gmaps4rails,我有一个包含30多个位置的阵列,我想在地图上显示。但是,我还没有找到一个源代码来演示如何迭代数组以使标记出现在地图上,而是选择严格硬编码地图lat/long值 例如,这是我目前拥有的代码,但它返回错误: allLocations = root.table.rows().data() root.forMap = [] for aLocation in allLocations root.forMap.push(aLocation[9] + ', ' + aLocation[10
allLocations = root.table.rows().data()
root.forMap = []
for aLocation in allLocations
root.forMap.push(aLocation[9] + ', ' + aLocation[10])
$('#multi_markers').map ->
handler = Gmaps.build("Google")
handler.buildMap
internal:
id: "multi_markers"
, ->
markers = handler.addMarkers(root.forMap)
handler.bounds.extendWith markers
handler.fitMapToBounds()
注意:我不能简单地使用ruby方法,因为表还必须与.js.coffee文件中的DataTable数据交互
如何在gmaps4rails方法中循环数组?既然处理程序.addMarkers获取数组,为什么不先使用jQuery.map并构建一个标记数组呢
all_locations = $.map root.table.rows().data(), (row)->
return {
lat: row[9],
lng: row[10]
}
$('#multi_markers').map ->
handler = Gmaps.build("Google")
handler.buildMap
internal:
id: "multi_markers"
, ->
markers = handler.addMarkers(allLocations)
handler.bounds.extendWith markers
handler.fitMapToBounds()
我对coffeescript很差劲-所以这可能不会直接起作用,但你应该了解总体思路。你读了自述文件了吗?但我需要在js.coffee文件的coffeescript中这样做,因为地图将与DataTable动态交互。我如何获得所有地图,不仅是第一个,而是所有30个,他们的数组是二维的,其中第二个维度是lat/long vlauesWant,用来聊天?