我需要在地图上的多个点之间绘制路径。我使用下面的代码绘制路径,但它不起作用,不会绘制任何路径。为什么以及如何解决这个问题?
var myTrip = [], waypts=[];
myTrip.push(new google.maps.LatLng(32.6384014, 51.65132887000004));
waypts.push({
location: new google.maps.LatLng(32.6384014, 51.65132887000004),
stopover: true
});
myTrip.push(new google.maps.LatLng(32.63727025, 51.65345639999998));
waypts.push({
location: new google.maps.LatLng(32.63727025, 51.65345639999998),
stopover: true
});
myTrip.push(new google.maps.LatLng(32.6367726, 51.65345639999998));
waypts.push({
location: new google.maps.LatLng(32.6367726, 51.65677270000003),
stopover: true
});
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer(
{
suppressMarkers: true,
suppressInfoWindows: true
});
directionsDisplay.setMap(map);
var request = {
origin: myTrip[0],
destination: myTrip[myTrip.length - 1],
waypoints: waypts,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
这是我的jsfiddle代码: jsfiddle geomap
答案 0 :(得分:0)
我的问题是来自点数的方式,来自谷歌参考: google map developers reference
允许的最大航点为8,加上原点和目的地。 Google Maps API for Work客户可以使用23个航点,以及原点和目的地。公交路线不支持航点。