从谷歌地图API文档中我得到了这个工作:
var flightPlanCoordinates = [
new google.maps.LatLng(37.772323, -122.214897),
new google.maps.LatLng(21.291982, -157.821856),
new google.maps.LatLng(-18.142599, 178.431),
new google.maps.LatLng(-27.46758, 153.027892)
];
我试图做的是用我自己的循环复制这段代码,这样我就可以使用以前存储的坐标,如下所示:
var output;
$.getJSON('DisplayMap.php', function(data) {
var output = "[ ";
for (var i in data.b) {
output+= "new google.maps.LatLng" + "(" + data.b[i].Ya + ", " + data.b[i].Za + ")," + " ";
}
output+= "]";
document.getElementById("placeholder").innerHTML=output;
alert(output);
});
output+= "]";
我检查了输出,它看起来完全符合我的要求。但是,当我像这样替换它时不起作用:
var flightPlanCoordinates = output;