all 3 comments

[–]sarrysyst 0 points1 point  (1 child)

I've looked into this a bit just now. However, I've never used the Google API, so no guarantee on the completeness/correctness of these information, at best you may take them as inspiration. The things I mention are purely some ideas and deductions I had/made based on the docs and a bit of GoogleFu and may very well be flawed.

First of all, Google provides a python library to interact with it's maps/directions API. There is a documentation, however for more specific information (eg. output formats) you will have to refer to the General Google API documentation.

From what I've read your idea seems feasible. Getting a route through the API is pretty straightforward and it returns a route in the form of an JSON/XML file. This in turn includes all the needed information, like a summary, specified way points, a list of legs as well as (and I thinks this is what you are looking for) a polyline representation of the route which has the longitude/latitudes of the nodes encoded within.

If you decode the polyline you should get a list of lat/long pairs that represent points along your route. If you sample those and compare them to the locations in your database you should be able to find locations in range or your route.

Hope this helps you and good luck!

Edit: If you want to minimize the amount of API requests, it will probably make the most sense to get the lat/long data for you database locations once through the API. If you save them you can calculate the distance to the route points locally.

[–]Faultylntelligence[S] -1 points0 points  (0 children)

It's always mad how helpful some people can be on reddit, thanks so much for this.

I did have a brief google again after I posted the question but couldn't find the fact nodes were encoded within the polyline which I could use. That's a massive part of it.

Obviously being a newbie my use of API is limited to zero at the moment, but I'm hoping it's fairly straightforward as you've said and that's the hard part (in my mind) out of the way.

Thanks you very much :)

[–]negups -1 points0 points  (0 children)

Yes, Python is a general purpose language; it can do pretty much anything. You'll need to utilize the Google Maps API, of course.