gpt4 book ai didi

javascript - 如何使用 JavaScript 动态构建路点数组?

转载 作者:行者123 更新时间:2023-12-03 08:54:55 25 4
gpt4 key购买 nike

从 WebAPI 我得到以下数组。

[
{
"Latitude": "-38.080528",
"Longitude": "144.363098"
},
{
"Latitude": "-38.080528",
"Longitude": "144.363098"
},
{
"Latitude": "-37.844495",
"Longitude": "144.873962"
},
{
"Latitude": "-37.785911",
"Longitude": "144.846497"
},
{
"Latitude": "-37.720763",
"Longitude": "144.978333"
},
{
"Latitude": "-37.777228",
"Longitude": "144.95636"
}
]

如何在运行时使用 JavaScript 构造路点数组。

预期输出应与以下内容匹配

var wayPointsArray = [
{location: new google.maps.LatLng(-38.080528,144.363098) },
{location: new google.maps.LatLng(-38.080528,144.363098) },
{location: new google.maps.LatLng(-37.844495, 144.873962) },
{location: new google.maps.LatLng(-37.785911, 144.846497) },
{location: new google.maps.LatLng(-37.720763, 144.978333) },
{location: new google.maps.LatLng(-37.777228, 144.95636) }
];

console.log(wayPointsArray);

enter image description here

最佳答案

这样就可以了:(当然,您的页面中需要有http://maps.googleapis.com/maps/api/js。)

var result = [];
for(i in data){
var element = {location: new google.maps.LatLng(data[i].Latitude, data[i].Longit
result.push(element);
}
console.log(result);

关于javascript - 如何使用 JavaScript 动态构建路点数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32548258/

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