Cambridge-Community-Kitchen / cck-volunteer-web-app

https://volunteer.cckitchen.uk
3 stars 2 forks source link

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

Open rhigman opened 6 months ago

rhigman commented 6 months ago

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 https://github.com/Cambridge-Community-Kitchen/cck-volunteer-web-app/blob/fcff3cf202e59caf10ff9ecf2d327038624975bd/components/deliveries-list/DeliveriesList.jsx#L78 3) for longer routes, have Route Pt 1/Route Pt 2 buttons? :frowning_face: 4) attempt a hack: based on aforementioned stackoverflow etc results, I discovered (by fiddling around in the URL bar) that replacing https://github.com/Cambridge-Community-Kitchen/cck-volunteer-web-app/blob/fcff3cf202e59caf10ff9ecf2d327038624975bd/components/deliveries-list/DeliveriesList.jsx#L80-L86 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.