将坐标从json移动到link(js)

时间:2018-01-03 13:10:19

标签: javascript jquery json google-maps

我有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);
        });
}

这是我得到的

enter image description here

我需要将这些坐标推送到此段path=50.72389,3.32214|51.72389,3.32214

的网址

我怎么能通过js做到这一点?

1 个答案:

答案 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);