到目前为止,我正在关注https://developers.google.com/maps/documentation/javascript/directions地图计算特定点之间的距离,但我需要它接收不同的值并根据这些值计算距离,我可以使用选择标签按如下方式执行,但我需要自动完成,因此当用户打开页面时,应将值发送到函数以计算距离。(我试图将值传递给 calcRoute 函数,但它不起作用)
另一个问题是我如何将列表(用于航点部分)传递给函数?
function calcRoute() {
var travel = document.getElementById("mode").value; << currently it is done manually
var origin = document.getElementById("origin").value; << manually
var request = {
origin: origin,
destination: '238 Elizabeth St,Los Angeles, CA',
waypoints:[{location: "George Street,Los Angeles,CA"}],
travelMode: travel
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}