根据谷歌地图,我可以规划一条跨越多个航路点的路线。这里有解释:http://code.google.com/intl/nl-NL/apis/maps/documentation/javascript/services.html#Routes
现在 api 要我像这样添加航路点:
location: waypoints
所以 waypoints 是一个数组,我必须将其分配给 location: 参数,但从我在演示中看到的情况来看,它们用位置字符串填充数组。我想知道是否可以传递纬度和经度而不是字符串?
更新:这是我尝试创建路线的部分。我现在已经在整个循环中将相同的值放在位置中,但是如果我既不使用变量值,id 也不起作用
function calcRoute() {
var waypts = [];
for (var i in owt.stores.spotStore.data.map) {
waypts.push({
location: new google.maps.LatLng(12.3, -33.6),
stopover:true
});
console.log(waypts);
}
var request = {
origin: new google.maps.LatLng(50.82788, 3.26499),
destination: new google.maps.LatLng(50.82788, 3.26499),
waypoints: waypts,
optimizeWaypoints: true,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
;
最佳答案
根据API reference :
A DirectionsWaypoint represents a location between origin and destination through which the trip should be routed.
location LatLng|string Waypoint location. Can be an address string or LatLng. Optional
因此创建一个具有经纬度值的新 Waypoint 应该如下所示
return {
location:new google.maps.LatLng(12.3, -33.6),
stopover:true
};
关于javascript - 显示路线的谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5425930/