Search code examples
google-mapsnavigationmapsopenstreetmapgpx

Convert Map Route to tracks or GPS Coordinates


From a navigation Route from Point A(coodinate/point) to Point B(coodinate/point) -

i want to know if i can convert them into a list of GPS coordinates(or traces), with some fixed interval i.e, these coordinates will trace out the path of the route


Solution

  • I found one way using OSRM If we send this request-

    We'll get the output in JSON format, where the locations are listed. Added a sample code which i made-

    URL = "http://router.project-osrm.org/route/v1/driving/"+args.coord+"?overview="+args.ovw+"&steps="+args.steps
    
    r=requests.get(URL, verify=False)
    data = r.json()    
    
    if data["code"]=='Ok':
        for i in range(len(data["routes"])):
            for j in range(len(data["routes"][i]["legs"])):
                for k in range(len(data["routes"][i]["legs"][j]["steps"])):
                    for l in range(len(data["routes"][i]["legs"][j]["steps"][k]["intersections"])):
                        locations_i.append(data["routes"][i]["legs"][j]["steps"][k]["intersections"][l]["location"])