我正在使用谷歌地图指示服务,如下所示:
directionsDisplay = new google.maps.DirectionsRenderer();
var directionsService = new google.maps.DirectionsService();
var start = arrObjLatLngs[0];
var end = arrObjLatLngs[arrObjLatLngs.length - 1];
arrObjWaypoints = [];
// Get waypoints
if (arrObjLatLngs.length > 2) {
for (var i = 0; i < arrObjLatLngs.length; i++) {
arrObjWaypoints.push({
location:arrObjLatLngs[i],
stopover:true}
);
}
}
var request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.DRIVING,
unitSystem: google.maps.DirectionsUnitSystem.METRIC,
provideRouteAlternatives: false,
waypoints: arrObjWaypoints
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
if (boolShowMap) {
directionsDisplay.setMap(MapObject);
$('#cp-div-map').dialog('open');
google.maps.event.trigger(MapObject, 'resize');
directionsDisplay.setDirections(response);
} else {
var total_distance = 0;
// Add up distance of all available legs
for (var i = 0; i < response.routes[0].legs.length; i++) {
total_distance += parseInt(response.routes[0].legs[i].distance.value);
}
callBack(total_distance);
}
}
});
基本上,第一位可以获得start
和end
之间的距离...但是,我还需要一个单独的值来计算base
和{{之间的距离1}}和第三个距离,介于start
和base
之间。
我试过这个: -
end
但这似乎覆盖了我发送的第一个请求。我对这个API不太熟悉,所以对此的任何帮助都会非常感激!
答案 0 :(得分:1)