我想从Google distance api的两点之间进行计算。有任何实现源代码链接可供实现。
文档链接是: https://developers.google.com/maps/documentation/directions/intro
答案 0 :(得分:0)
这是我的解决方案。希望这有帮助:)
function getDistance(from, to){
var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix(
{
origins: [from],
destinations: [to],
travelMode: google.maps.TravelMode.DRIVING,
unitSystem: google.maps.UnitSystem.METRIC,
avoidHighways: false,
avoidTolls: false
}, function(response, status){callbackFunc();});
}
function callbackFunc(response, status){
if (status != google.maps.DistanceMatrixStatus.OK)
{
console.log('Error was: ' + status);
}
else
{
var from = response.originAddresses;
var to = response.destinationAddresses;
for (var i = 0; i < from.length; i++) {
var results = response.rows[i].elements;
for (var j = 0; j < results.length; j++) {
console.log(results[j].distance.value);
}
}
}
}
答案 1 :(得分:0)