1
我正在嘗試使用谷歌距離矩陣製作一個旅行計算器,我試圖從點a到點b得到距離計算,然後從點b返回到點一個。我通常只需加上兩個以獲得總距離值,但由於單向街道和高速公路路口等原因,一條路線可能比另一條路線長。Google距離矩陣返回4組結果來自2組開始/目的地
我使用下面的代碼:
getdistance:{
options:{
origins:["pe219px","ng323rj"],
destinations:["pe219px","ng323rj"],
travelMode: google.maps.TravelMode.DRIVING,
unitSystem: google.maps.UnitSystem.IMPERIAL
},
callback: function(results, status){
var html = "";
if (results){
for (var i = 0; i < results.rows.length; i++){
var elements = results.rows[i].elements;
for(var j=0; j<elements.length; j++){
switch(elements[j].status){
case "OK":
var sd=$(this).text();
html += parseInt(elements[j].distance.text) + "<br />";
break;
case "NOT_FOUND":
html += "The origin and/or destination of this pairing could not be geocoded<br />";
break;
case "ZERO_RESULTS":
html += "No route could be found between the origin and destination.<br />";
break;
這給我結果:
1
25
26
1
我不知道哪裏的都來自1,我可以看到,25嗎? 26回來了,但爲什麼那裏呢?
我不得不看看下面的帖子: Google Maps DistanceMatrix
它建議使用:
origins: [base],
destinations: [start, end],
這將返回:
25
1
我也曾嘗試的開始和結束其他方式給我:
1
26