Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting more than 8 waypoints in Google Maps v3

Migrating code from Javascript API 2 to 3. I have a list of locations which i need to plot in the form of a driving directions. This was done in v2 using the following code

directions = new GDirections(map);
directions.loadFromWaypoints(waypoints, {preserveViewport: true});  

Here is my attempt at converting this to V3

var request = {
    origin: startLoc,
    destination: endLoc,
    waypoints: waypoints,
    optimizeWaypoints: true,
    travelMode: google.maps.TravelMode.DRIVING
};          

directionsService.route(request, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);
    } 
});

Not the whole code, but the general idea. Seems to work fine, with one little issue. When there are more than 8 waypoints, the call fails. This is expected since Google Maps API v3 Docs states

The maximum allowed waypoints is 8, plus the origin, and destination. Maps API for Business customers are allowed 23 waypoints, plus the origin, and destination. Waypoints are not supported for transit directions.

Since i didn't run in to this issue in v2, is this a new restriction with v3? I wonder if i am using something that was not designed for what i need. This is a very lightly used applicaton with 2 users, so i am not sure if an expensive business license is worth the return. Emails to Google maps team have not yet been returned. Any workarounds/pointers will be of great help. Thanks.

like image 402
BBS Avatar asked Nov 07 '13 23:11

BBS


People also ask

How many waypoints can you have on Google Maps?

You can add up to nine stops on Google Maps.


1 Answers

One possible work around (particularly for a lightly used site) is to use multiple DirectionsService requests.

  • example 1 (addresses)
  • example 2 (coordinates)
like image 192
geocodezip Avatar answered Oct 05 '22 03:10

geocodezip