I am trying to generate random points on a route from one point to another. What I have till now is, given a source and a destination, I can get a route using Google's API. But how do I get the coordinates of random points on the route?
I'm not sure what tool you are using, but look into linear referencing methods.
For example, if you are using PostGIS, here are 10 random points along a linestring:
SELECT ST_Line_Interpolate_Point('LINESTRING (10 20, 50 60, 80 30, 140 60)', random()) FROM generate_series(1,10)
Or if using Shapely:
from random import random from shapely.geometry import LineString line = LineString([(10, 20), (50, 60), (80, 30), (140, 60)]) for i in range(10): pt = line.interpolate(random(), True) print(pt.xy)