我试图将地图上的不同标记链接在一起。目前,标记已经过硬编码,但它们将通过平板电脑及时发送GPS位置进入网站。无论出于何种原因,如果我输入的标记超过10个,则折线不再显示。有人可以帮我弄清楚为什么会这样吗?感谢。
<html>
<head>
</head>
<body>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geocoder;
var map;
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var locations = [
['16:58', -20.1672799707871, 57.5069032768888],
['17:00', -20.170670813731, 57.5032840805832],
['17:01', -20.1712602810727, 57.502503950733],
['17:04', -20.166955925865, 57.4892648490453],
['17:07', -20.1761991610139, 57.4822988090064],
['17:10', -20.1961753165077, 57.4824656045157],
['17:13', -20.220309405427, 57.487469732469],
['17:16', -20.2342861943874, 57.4996038055266],
['17:19', -20.2419951166671, 57.4924547310887],
['17:22', -20.2418197976697, 57.4838445649936],
['17:25', -20.2417927882899, 57.4821667460937],
['17:28', -20.244868944177, 57.4761929726994],
['17:31', -20.2494147017248, 57.4751336596163],
['17:34', -20.2529453707358, 57.4698643969492],
['17:37', -20.2515653985995, 57.4694827601669]
];
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: new google.maps.LatLng(-20.23, 57.49),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
directionsDisplay.setMap(map);
var infowindow = new google.maps.InfoWindow();
var marker, i;
var request = {
travelMode: google.maps.TravelMode.DRIVING
};
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]), map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
if (i == 0) request.origin = marker.getPosition();
else if (i == locations.length - 1) request.destination = marker.getPosition();
else {
if (!request.waypoints) request.waypoints = [];
request.waypoints.push({
location: marker.getPosition(),
stopover: true
});
}
}
directionsService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(result);
}
});
}
google.maps.event.addDomListener(window, "load", initialize);
</script>
<div id="map" style="width: 100%; height: 100%">
</div>
</body>
</html>
答案 0 :(得分:0)
您不能绘制超过8点的折线宽度加上起点和终点:
MAX_WAYPOINTS_EXCEEDED表示请求中提供的航路点太多最大允许航点为8,加上原点和目的地。 (Google Maps API for Work客户可能包含最多包含23个航点的请求。)
这是因为免费API仅限于:
免费API的用户每个请求最多允许8个航路点(加上始发地和目的地),每24小时一次总共2,500个路线请求。
尝试将折线拆分为多个请求