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

How to build an array of Way Points dynamically using JavaScript?

我从 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);

这样做:(当然,您需要在您的页面中提供 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);