在路线中显示多个航点

时间:2013-04-26 11:52:28

标签: google-maps google-maps-api-3

在Google Map V3中需要帮助 我想在路线中显示多个点。 目前我已经提到了原点和目的地,但是如何显示我在航点(arrWaypoints)数组中的所有点? 以下是我的代码。

var origin = arrWaypoints[0];
var destination = arrWaypoints[1];
this.directions.route({
                    origin: origin,
                    destination: destination,
                    travelMode: google.maps.DirectionsTravelMode.DRIVING,
                    unitSystem: google.maps.DirectionsUnitSystem.METRIC
                }, function(result, status) {
  ........

谢谢, 沙拉斯

1 个答案:

答案 0 :(得分:0)

在您的示例中,没有要显示的航点。如果您要包含其他航点,请求将如下所示:

var origin = arrWaypoints[0];
var destination = arrWaypoints[arrWaypoints.length-1];
// Origin and destination don't need to be in the arrWaypoints anymore as they're listed separately in the request.
arrWaypoints.splice(arrWaypoints.length-1, 1);
arrWaypoints.splice(0, 1);
this.directions.route({
                origin: origin,
                destination: destination,
                waypoints: arrWaypoints,
                travelMode: google.maps.DirectionsTravelMode.DRIVING,
                unitSystem: google.maps.DirectionsUnitSystem.METRIC
            }, function(result, status) {
  ........