我有js代码从后端获取数据
这是代码:
var speeddata = [];
function getSpeedData() {
var googleurl =
"https://roads.googleapis.com/v1/speedLimits?path=50.72389,3.32214|51.72389,3.32214&key=8IAceOk43NpWKpczMAzN5dVosUI=";
$.getJSON(googleurl, function (data, status) {
speedlimits = data;
console.log(speedlimits);
});
var url = $('#getData').data('request-url');
$.getJSON(url,
function (data) {
speeddata = data;
console.log(speeddata);
});
}
这是我得到的
我需要将这些坐标推送到此段path=50.72389,3.32214|51.72389,3.32214
我怎么能通过js做到这一点?
答案 0 :(得分:1)
你可以试试这个:
var speeddata = [{Latitude2: 51.72389,Longitude2: 3.32214, Speed: 41},{Latitude2: 51.72389,Longitude2: 3.32214, Speed: 41}];
var args = 'yourpath = ';
for(var i=0; i < speeddata.length; i++){
args += speeddata[i].Latitude2 + ',' + speeddata[i].Longitude2;
if(speeddata.length == (i+1)){
break;
}else{
args += '|';
}
}
console.log(args);