Note that there are some explanatory texts on larger screens.

plurals
  1. POFit Bounds in Google Map Render Directions
    primarykey
    data
    text
    <p>I am trying to render directions for 48 waypoints, but google only allows 8 waypoints to be rendered per request. so I do multiple requests (in my case 6). However, the API somehow doed fitBounds() for the last request.</p> <p>How can I show all the 48 waypoints in one map using fitBounds() and/or setZoom()</p> <p>My code is as below: - </p> <pre><code>function DisplayDirection(directionList){ var interval = 8; // upper bound for usage limits in google directions API is 8 var startIndex =0; var maxmimumIndex = directionList.length-1; // Total number of waypoints in this route var partialEndIndex = interval-1; // end waypoint at start var iteration = 0; // loop controler directionsService = new google.maps.DirectionsService(); var resultSet = new Array(); var directionsDisplayList = new Array(); var resultsCached = 0; var bounds = new google.maps.LatLngBounds(); do { //do...while to iterate over multiple requests iteration++; if(iteration&gt;1){ startIndex = startIndex+interval; partialEndIndex = startIndex+interval; } var directionsDisplay = new google.maps.DirectionsRenderer({ markerOptions: { visible:false } }); directionsDisplayList.push( directionsDisplay ); directionsDisplayList[iteration-1].setMap(map); var origin = directionList[startIndex]; var destination = partialEndIndex &lt; maxmimumIndex ? directionList[partialEndIndex]:directionList[maxmimumIndex]; waypoints = new Array(); for(var i=startIndex+1;i&lt;partialEndIndex;i++){ if(i&gt;maxmimumIndex){ break; } waypoints.push( { location:directionList[i], stopover:true } ); latlong = directionList[i].split(","); // lat = latlong[0]; // lng = latlong[1]; // bounds.extend (new google.maps.LatLng(lat,lng)); //extend the bounds } var request = { origin: origin, destination: destination, waypoints : waypoints, provideRouteAlternatives:false, travelMode: google.maps.TravelMode.WALKING, unitSystem: google.maps.UnitSystem.METRIC } directionsService.route(request, function(result, status) { if(status == google.maps.DirectionsStatus.OK) { //Cashe the results to render directions// resultSet.push(result); if(resultSet.length==iteration){ for(var i=0; i&lt;iteration; i++){ directionsDisplayList[i].setDirections(resultSet[i]); } map.fitBounds(bounds); } } }); }while (partialEndIndex &lt;= maxmimumIndex); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload