我有一个带有30+位置的数组,我想在地图上显示。但是,我还没有找到一个源代码来演示如何迭代数组以便标记出现在地图上,而是选择严格地硬编码map lat/long值。
例如,这是我目前拥有的代码,但它返回错误:
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方法,因为表还必须与DataTable文件中的.js.coffee数据交互。
如何循环遍历gmaps4rails方法中的数组?
发布于 2014-11-05 02:03:53
既然handler.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()https://stackoverflow.com/questions/26748320
复制相似问题