Skip to content

Google Bike/Driving Routes miss out waypoints for routes with more than 9 drops #29

@rhigman

Description

@rhigman

Check a current active route link for any long route for an example. The route starts and ends at the Lockon but the last (n-9) drops will be missing.

Apparently, there's a limit on the number of waypoints a route can have when using the free version of the Maps API (source: lots of stackoverflow etc results for similar complaints).

Possible workarounds:

  1. don't display the Route buttons for longer routes, to avoid confusion
  2. mitigate by removing any duplicate waypoints before calculating route, e.g. at
    const plusCodes = routeData.deliveries.map(item => item.plus_code);
  3. for longer routes, have Route Pt 1/Route Pt 2 buttons? ☹️
  4. attempt a hack: based on aforementioned stackoverflow etc results, I discovered (by fiddling around in the URL bar) that replacing
    const googleRouteUrl = `${ googleRouteBaseUrl }/?api=1&origin=${
    originForUrl
    }&waypoints=${
    plusCodes.map(encodeURIComponent).join('|')
    }&destination=${
    originForUrl
    }`;

    with something like
  const googleRouteUrl     = `${ googleRouteBaseUrl }/{
    originForUrl
  }/{
    plusCodes.map(encodeURIComponent).join('/')
  }/{
    originForUrl
  }`;

does actually show all the waypoints. (It ignores travelmode, though, even when the & is corrected to ?, which would be misleading for cyclists as the default is car.) Using URL hacking rather than the proper API would be brittle, though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions