在Google Maps API V3中操纵JSON数据创建lat/lngs的javascript数组
我试图使用从MySQL检索的lat/lng值来创建一个用于GMAPSAPI的航路点数组。我有下面的代码,但由于我有限的javascript知识,我很难将检索到的数据推送到javascript数组中定义为航路点数据 我已经看过一些在线示例,到目前为止,我已经成功地获得了一个解析脚本,可以毫无问题地检索数据,并在我实例化地图的页面中调用它:在Google Maps API V3中操纵JSON数据创建lat/lngs的javascript数组,javascript,arrays,json,google-maps-api-3,Javascript,Arrays,Json,Google Maps Api 3,我试图使用从MySQL检索的lat/lng值来创建一个用于GMAPSAPI的航路点数组。我有下面的代码,但由于我有限的javascript知识,我很难将检索到的数据推送到javascript数组中定义为航路点数据 我已经看过一些在线示例,到目前为止,我已经成功地获得了一个解析脚本,可以毫无问题地检索数据,并在我实例化地图的页面中调用它: makeRequest('parsedata.php', function(data) { var data = JSON.parse
makeRequest('parsedata.php', function(data) {
var data = JSON.parse(data.responseText);
for (var i = 0; i < data.length; i++) {
displayLocation(data[i]);
}
});
基本上,我不知道如何操作这个输出来创建所需的lat/lngs javascript数组,作为我在页面上运行的directions服务实例的航路点
和往常一样,任何指点都很受欢迎。干杯。//为航路点创建一个数组
//create an array for the waypoints
var waypoints=[];
//only up to 8 waypoints are allowed without business-license
for(var i=0;i<8 && i<data.length;++i) {
//push a LatLng-object to the array
waypoints.push(new google.maps.LatLng(data[i].lat,data[i].lng));
}
//use the waypoints
//doSomethingWith(waypoints);
var航路点=[];
//无营业执照,最多只能使用8个航路点
对于(var i=0;除非您告诉我们,否则对阵列进行进一步处理的要求只有您自己知道。@amadeus如果我最初的问题没有完全阐明我要实现的目标,我很抱歉。请从谷歌参考资料中转述:航路点[]指定方向航路点数组。航路点通过在指定位置路由来改变路线。通过以下字段将航路点指定为对象文字:location指定航路点的位置,可以是LatLng,也可以是将进行地理编码的字符串。stopover是一个布尔值,表示航路点是路线上的一个站点,具有将路线拆分为两条路线的效果。而@amadeus则是getting坐标从我当前的数据中移到了我无法做到的新数组中。希望这更有意义。再次感谢
[{"itineraryID":"6","coursesID":"20","coursename":"Carnoustie Championship Course","lat":"56.497414","lng":"-2.720531"},{"itineraryID":"6","coursesID":"21","coursename":"Troon Old Course","lat":"55.534203","lng":"-4.642833"}]
//create an array for the waypoints
var waypoints=[];
//only up to 8 waypoints are allowed without business-license
for(var i=0;i<8 && i<data.length;++i) {
//push a LatLng-object to the array
waypoints.push(new google.maps.LatLng(data[i].lat,data[i].lng));
}
//use the waypoints
//doSomethingWith(waypoints);