Note:
The results returned by this script is VERY approximate - could easily miss better alternatives. If interested this is how it works:
- Driving Directions are fetched for the entered addresses
- A search for the 'via' string is made at discrete points along the route (each fetching just 4 results)
- All the points are checked for their distance from a point along the route (straight line distance)
- The closest result is inserted as a real via point in the directions which are fetched again
This strategy is a reasonable proof of concept, but as you can see from the wild assumptions made above, its far from perfect. YMMV