Matrix 谷歌距离矩阵API 3

Matrix 谷歌距离矩阵API 3,matrix,distance,Matrix,Distance,我有使用谷歌距离矩阵API计算到另一个地方的距离的代码,但是免费的,每个查询只有100个元素。所以我用循环代码来解决这个问题,比如元素,我的代码是PHP,javascript,我从MySql解析纬度和经度数据。有人知道我下面的代码有什么错误吗?因为如果我点击“计算”按钮,它不会显示任何内容。实际上,我已经修改了这个URL中的代码,这是我的代码: function hitung (){ service = new google.maps.DistanceMatrixService();

我有使用谷歌距离矩阵API计算到另一个地方的距离的代码,但是免费的,每个查询只有100个元素。所以我用循环代码来解决这个问题,比如元素,我的代码是PHP,javascript,我从MySql解析纬度和经度数据。有人知道我下面的代码有什么错误吗?因为如果我点击“计算”按钮,它不会显示任何内容。实际上,我已经修改了这个URL中的代码,这是我的代码:

function hitung (){
  service = new google.maps.DistanceMatrixService();
    for (m = 0 ; m < l-80 ; m++ ){
        asal = originarray[m];
        for (n = 0 ; n < l-80 ; n++ ){
            tujuan = destarray [n];
            calculateDistances();
        }
    }
  }
  function calculateDistances() {

 //var s = 0;

  //for (m = 0 ; m < l-80 ; m++ ){
    //  asal = originarray[m];
    //for (n = 0 ; n < l-80 ; n++ ){
        //servicearray[s] = new google.maps.DistanceMatrixService();
        //tujuan = destarray [n];       
        service.getDistanceMatrix(
      {
       //origins: [origin1, origin2],
      // destinations: [destinationA, destinationB],
       origins: asal,
     destinations: tujuan,
        //origins: originarray,
        //destinations: destarray,
        travelMode: google.maps.TravelMode.DRIVING,
        unitSystem: google.maps.UnitSystem.METRIC,
        avoidHighways: false,
        avoidTolls: false
      }, callback);
     // s++;

    //}

// }        
  }

  function callback(response, status) {
    if (status != google.maps.DistanceMatrixStatus.OK) {
      alert('Error was: ' + status);
    } else {
      var origins = response.originAddresses;
      var destinations = response.destinationAddresses;
      var outputDiv = document.getElementById('outputDiv');
      //outputDiv.innerHTML = '';
     // deleteOverlays();

      for (var i = 0; i < origins.length; i++) {
        var results = response.rows[i].elements;
       // addMarker(origins[i], false);
        for (var j = 0; j < results.length; j++) {
        //  addMarker(destinations[j], true);
          outputDiv.innerHTML += origins[i] + ' to ' + destinations[j]
              + ': ' + results[j].distance.text + ' in '
              + results[j].duration.text + '<br>';
        }
      }
    }
  }

  function addMarker(location, isDestination) {
    var icon;
    if (isDestination) {
      icon = destinationIcon;
    } else {
      icon = originIcon;
    }
    geocoder.geocode({'address': location}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        bounds.extend(results[0].geometry.location);
        map.fitBounds(bounds);
        var marker = new google.maps.Marker({
          map: peta,
          position: results[0].geometry.location,
          icon: icon
        });
        markersArray.push(marker);
      } else {
        alert('Geocode was not successful for the following reason: '
          + status);
      }
    });
  }

  function deleteOverlays() {
    if (markersArray) {
      for (i in markersArray) {
        markersArray[i].setMap(null);
      }
      markersArray.length = 0;
    }
  }

</script>
函数hitung(){
service=new google.maps.DistanceMatrixService();
对于(m=0;m';
}
}
}
}
功能添加标记(位置、isDestination){
var图标;
如果(isDestination){
图标=目的地;
}否则{
图标=原始图标;
}
geocoder.geocode({'address':location},函数(结果,状态){
if(status==google.maps.GeocoderStatus.OK){
extend(结果[0].geometry.location);
映射边界(bounds);
var marker=new google.maps.marker({
地图:善待动物组织,
位置:结果[0]。geometry.location,
图标:图标
});
markersArray.push(marker);
}否则{
警报('地理代码未成功,原因如下:'
+地位);
}
});
}
函数deleteOverlays(){
if(markersArray){
for(markersArray中的i){
markersArray[i].setMap(空);
}
markersArray.length=0;
}
}

通过记录响应,检查您是否收到谷歌的响应

function callback(response, status) {
    console.log(response);
}

我也有同样的问题,但我认为问题在于您的数组(tujuan和asal)。我试图解决这个问题,但没有找到答案。如果你找到答案,你能把它寄到这里吗?如果我发现了,我也会这么做。