Find Routes within Range of a Point - mysql

I am seeking a way using Google Maps to take a predefined latlng point and find routes that pass within 20 miles. The start and end points for the route exist in a MySQL DB.
Would it be best, when storing the routes, to include all the polylines that make up the route?
Should I store the RouteBoxer coordinates and find all boxes that contain the predefined latlng point? This may be up to 3x greater distance then 20 miles
How should I store the data for both predefined latlng points and the route information?
EDIT:
This article may bring some ideas but I am still unsure of the best method? I am concerned with scaling because I am thinking of 50,000+ routes and thousands of routes.
--> Find how many (googlemap) polygons near x distance of a point
--> Get polygons close to a lat,long in MySQL
--> MySQL Find Polygon Nearest to Point
Thanks very much!
David

Related

Google maps waypoints limit - show long routes accurately from raw GPS data

I am well aware that this question was asked many times and i've spent days looking through stackoverflow answers but couldn't find anything that goes behind workarounds.
The problem is pretty simple: we need to show exact routes passed by the car (so, from GPS long/lat history data) on google maps and the routes are hundreds or even thousands kms long. What that mean is that we will always exceed waypoints limits by at least an order of magnitude (8 for free or 25 for premium). My gut is telling me that batching GPS locations to batches of 8/25, sending many requests that way and then snap all of those to roads and at the end merge all together into a single route is a bit wild solution.
If we are on a highway then its not that big problem since snap and expected/calculated route will work but if some long route is a combination of highway but also in-town drive through small streets with alot of turning, then i can imagine huge discrepancy between an actual (from raw GPS data) and shown route.
I am wondering if i am missing something? Is there some 'more proper' way to approach this problem?
PS.
I don't need any code at the moment, just a proper way to architecture the idea.
Thanks
[UPDATE]
To put a few numbers into the mix:
1) average route distance is about 1800kms
2) number of raw GPS points generated is about 15000-18000 (every 100-150 meters)
3) number of points that the route must go through (waypoints) is in at least in hundreds and sometimes in thousands (when most of the route is in urban areas)
One possible solution is the Roads API.
Related questions:
draw a path from GEO locations from GPS snapped to road
Google Map Road API not interpolating path and not giving smooth route
Issues
The Roads API doesn't seem ready for prime time (reports of inconsistent results in the issue tracker)
Issue 9436: Roads-API - Snapping point defects
has a limit of 100 points at a time with a (not documented) recommended maximum separation of 400m (reference a comment under the answer to Google Map Road API not interpolating path and not giving smooth route).
You could render the routes as images yourself and load them as an overlay layer on top of google maps.
For example in my website we render weather forecast layers and add them as layers on top of the base map:
http://www.weather.gr/en/maps.aspx

Given a list of GPS positions, how do I display route using Google Maps API

I have lists of between 100 and 10000 GPS location from vehicles driving around during some timespan.
I want to display that on a Google Map, using their API (with the Business licence if that matters).
As I see it, there are 3 options, all with problems:
1) Draw a polyline between all positions. Some positions are not that accurate so it looks like the route hits some buildings next to the road. I know that all positions are on a road. Also, it cuts some corners, and it doesn't look professional.
2) Display just the GPS positions in the map. This is not good either since the GPS positions are off the road (which they shouldn't be).
3) Draw the route using Maps API. This limits us to using 23 waypoints between the start and end positions. The route looks excellent and it follows the road (GPS positions next to the road are moved to the road automatically). But especially for longer time spans, this option means that the route displayed is incorrect (Google guesses the route taken between the waypoints - so from the 10000 GPS positions it only uses 23). And we can't display a clearly incorrect route.
Does anyone have a good/better way to show a driven route on Google Maps that follows the road but takes into account all/many given GPS positions?
Could you not chain the route using the maps API? It's not something I've done before so this answer could be a little vague but would it not be possible to segment your list of coordinates into chunks of 23 fire the requests and then display the resultant routes on the map?
I'm not overly sure on the return format so it may be necessary to mess with the output in order to give the illusion of the route, also you will likely not need to use every coordinate (perhaps exclude those that are within a small distance of each other for example being stuck at lights), otherwise the requests may take a long time.
We've actually moving away from option 3. The reason is that when the positions get moved to the nearest road, that is not always correct (like if you're driving on a parking lot), so since that doesn't always give the correct route, then we'll not take that path.
So I don't know if it's possible to chain several routes in the same map.

How accurate is the Lat/Lng that you get from SV API's getPosition()?

I am asking the same question on Google's product forum, so excuse me if you see the same question.
I am using Street View Service to develop my application that is similar to this example (figure above). In this application, I want to store where, in lat/lng coordinates, users have traveled on the map. I figured out StreetViewPanorama class provides an API, getPosition(), and this returns LatLng. Lat/lng coordinates you extract from LatLng object look like lat=38.924066 and lng=-77.032172. I can use these values to store what I want.
Although the aforementioned latlng values have 8 significant figures, I was actually wondering how accurate these values are, because GPS locations that Google collects while running a Street View car would have errors.
So my question is, how accurate is the latlng value returned by getPosition()? In other words, how much concordance can I expect between latlng values from getPosition() and latlng position on Google Map?
Thank you very much!
I got an answer in another forum so I copy it over here too and mark the question as solved. The following is the answer from barryhunter in Google Forum.
A 6dp lat/long is on the order of precise to 0.1m. (ie 10cm)
So such a lat/long should match up very precisely with the Google Map.
Ie its a precise location.
But as to how accurate the underlying map is, that varies a lot. Its
almost impossible to tell. Most locations I would estimate to be
within about 6-30m
You can check the accuracy of a lat or a lng value with 6 decimal points in the following page:
http://nearby.org.uk/precision-ll.cgi?lat=38.924066&long=-77.032172
As indicated in the above answer, the real limitation is the positioning of the map, not the numerical value obtained from it.
For example, I happened to be taking readings at a location where two Google Map sections overlapped. There was an obvious discontinuity in color and terrain features when going from one to the other. The photos must have been taken at least a year apart.
A marker placed on one side of this overlap jumped by at least 10 m when viewed on the other overlapping section. In other words, one (or both) map sections were off by at least a few meters relative to the true GPS coordinates.
If you are lucky enough to be working on a single section, distances between map points are probably quite accurate, but if you check a point against the actual GPS coordinate on the ground, who knows? A bias error of 6-30m seems likely to me.

check whether a point lies in a route - Google maps

I need to highlight relevant locations in a google map when a user requests for a route.
I have found a few steps to implement. But got stuck at one point.
Let's assume that we have a collection of large number of points (a few thousands). We need to find out which of them lie in a (dynamic) route.
Step1: First filter out the points based on the route. That means, find the max-lat, min-lat, max-lon, min-lon of the route and apply this filter out to our group. So that we can figure out a lesser number of eligible candidates.
Step2: We can still filter out the unnecessary points using a utility library called RouteBoxer. (http://google-maps-utility-library-v3.googlecode.com/svn/tags/routeboxer/1.0/examples/routeboxer-v3.html)
Step3: After above 2 steps, we have reduced the number of points to a few hundred from a few thousand. And these points would be somewhere around that route, though not exactly on it. This is where I face the challenge. How to check whether these points lie in that route? I dont think getting all the points a route and check the distance is a good solution (yeah, it will work. but..) as the route can be of any distance. Is there any way to check the minimum distance between a point and a route?
RouteBoxer will give you a list of polygons or LatLngBounds (if if gives polygons you can get LatLngBounds fron it anyway). You can cycle through each of your points and check if that point lies on any of those bounds using the contains method of LatLngBounds class.
Yes, there is dijkstra or kruskal algorithm.

Points within n km's of route / path

I would like to use the Google maps API to generate a route between my client's offices and one of their customers.
I would then like to find any customers (from my internal database) that are located within e.g. 10 miles either side of that route.
Basically I want to replicate this functionality:
http://gis5.com/pois_along_route/gm_pois_along_route.php
I'd appreciate any pointers that you may have on this
In general, you have to find distance from a given point (your customer) and a polyline (the route). The route from the google directions response is divided into legs, and the leg is consisted of multiple steps... In each step, you have path[] array of locations (pair of latitude and longitude). Let's call each location in the path[] array, a "Vertex".
You have to iterate through all vertices in the route (get all vertices from all steps in the route) and calculate the distance between the polyline created from the current "observed" vertices and the yours POI (Points of Interest - the Customers)
The shortest distance can be calculated by presenting the two vertices & the Customer's location as nVector. After this, by doing Vector cross product of the vectors you find the shortest (orthogonal) distance between the point and the polyline
I had similar problem recently and I solved it that way. I got the idea from the examples Here (look at the DISTANCE POINT TO POLYLINE OR POLYGON example Source code)
If you are confused from the Math involved, maybe this link might help you by explaining the concept of a Vector Cross Product. Also this could also help you to understand the nVector concept.
Because this kind of calculating the distance is pretty much time consuming (if you have many customer locations in the database), you might be interested of filtering some of the locations from the database and not performing calculations for them...look at my answer on this question about how to do filtering on locations based on the route that is shown on the map.
Hope this helps and give you some basic idea on how to start solving your problem. It took me a lot of time till to figure it out. Cheers.