将数组转换为谷歌纬度/液化数组
Convert Array to Google Lat/Lng Array?
我有数组
[[[11.11,11.11],[22.22,22.22],[33.33,33.33]],[[11.11,11.11],[22.22,22.22],[33.33,33.33]]]
我想做的是把它变成,
var paths = [[
new google.maps.LatLng(38.872886, -77.054720),
new google.maps.LatLng(38.872602, -77.058046),
new google.maps.LatLng(38.870080, -77.058604),
new google.maps.LatLng(38.868894, -77.055664),
new google.maps.LatLng(38.870598, -77.053346)
], [
new google.maps.LatLng(38.871684, -77.056780),
new google.maps.LatLng(38.871867, -77.055449),
new google.maps.LatLng(38.870915, -77.054891),
new google.maps.LatLng(38.870113, -77.055836),
new google.maps.LatLng(38.870581, -77.057037)
]];
其中每个
[[11.11,11.11],[22.22,22.22],[33.33,33.33]]
我的数组是一个新的数组Google LatLng Markers。
我尝试在数组上使用地图函数,如下所示:
point.map(new google.maps.LatLng(point))
但是得到一个 NaN 错误。我是否需要打破每个点,或者我可以通过诸如map之类的调用更流畅地执行此操作?
嵌套循环?
var input = [
[
[11.11, 11.11],
[22.22, 22.22],
[33.33, 33.33]
],
[
[11.11, 11.11],
[22.22, 22.22],
[33.33, 33.33]
]
];
var paths = [];
for (var i = 0; i < input.length; i++) {
var path = [];
for (var j = 0; j < input[i].length; j++) {
path.push(new google.maps.LatLng(input[i][j][0], input[i][j][1]));
}
paths.push(path);
}
console.dir(paths);
在这里演示
相关文章:
- 如何在映射数组中添加换行符
- javascript结合了数组和字典
- 需要帮助设置json数组
- 不能从angular2中的子组件指定父组件中的数组
- 使用JS将数组转换为json对象
- 数组在递归方法中设置为null
- knockoutjs可观察数组
- Javascript-如何读取json文件中的列并将其保存在Javascript数组中
- 将数组从PHP传递到Javascript
- JavaScript数组排序(函数)用于对表行进行排序,而不是排序
- 在函数中添加数组元素的数值
- 无法通过数组映射绑定
- javascript中的数组出错
- 如何使用 node.js 比较两个 json 数组
- Javascript(Angular)从一个对象数组到第二个数组查找值
- 根据id将json数组组合为一个json数组
- 将数组转换为谷歌纬度/液化数组
- 从数组中绘制纬度,在谷歌地图中做长
- 谷歌地图标记数组,我如何得到经度/纬度
- 将一个占位符的经度和纬度存储到数组中