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

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.

Related

How to avoid drawing a route when point is not in a road

The First picture shows the real path
And the Second one show the result given by rounting services
(Here Maps or Bing maps)
any idea ?
If you try to calculate a route with a point that isn't on a road, it will snap to the nearest road if one is within about 150 meters. There is no option to avoid this. I believe all major mapping platforms do the same thing.

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

Getting all streets visible in Google map's viewport

I'm trying to build a map with the following algorithm:
Wait for pan or zoom to occurs.
Query for all streets visible in the viewport (extent).
Color every visible street with a predefined color.
Example:
I want to show the numbers of businesses on each street, or the number of crimes committed at each street.
I have a DB which holds this kind of information (streetname, data), but each row doesn't have the location data.
Therefore, after each map zoom or pan, I cannot query all of it by a geographical bounding rectangle, it will be far more efficient to use Google own DB and query it by street names.
I know how to register to pan and zoom events.
I know how to calculate the viewport coordinates.
I know how to color a single street.
How can I get a list of all streets visible in the viewport?
Any other solutions or architectures are welcome.
The preferred solution will not use Google DirectionsService nor DirectionsRenderer since they slow down the map.
My understanding is that what you are asking is not possible from Google API's. Reverse geocoding inside a polygon is not a service they offer. There are some posts on other sites (e.g. https://gis.stackexchange.com/questions/22816/how-to-reverse-geocode-without-google) with the reference gisgraphy.com looking like a pretty neat reverse geocoding tool.
This still does not address your all streets in a polygon problem however. I think your only option would be to get your hands on the data (Open Street Maps) and write the code yourself. Further - if you are going to do this for a large area I would take an approach like I recommended here with grids: https://stackoverflow.com/a/18420564/1803682
I would create my grid elements, and for each street calculate all the grids to which it belongs and store in the database. Then when you search a polygon, you would calculate all the grids the polygon overlaps, and can then test the subset of road data in each of those squares to determine overlap.
I looked into this and abandoned a similar requirement a few months back and still have a desire to implement it. Most of the point/line in polygon work is happening on data created in my application (i.e. not street data) and right now that is the only data I will be including. What I am trying to say is - I hope someone gives you a better answer.
Update:
For what you are asking I still believe you will need to use a mix of your own database based on OpenStreetMap and some kind of grid analysis carried out in advance. If you have some time to commit to the project this should not be too awful to process. The database will be large, and the calculations needed will likely require a significant amount of one-time / upfront processing time. As far as highlighting routes/roads/whatever within the viewport, there are lots of way to accomplish this using the API - example here which I found useful: polyline snap to road using google maps api v3
Also useful: http://econym.org.uk/gmap/snap.htm
Note that one way streets may give some grief if using the directions api to snap to a street and you will likely have to watch for this and correct or reverse the start/end points.
Google would recommend using it's Geocoding Service in order to populate your data base with the co-ordinates. You can then use the LatLng Bounds Class method "contains" to check whether your points lie within the viewport. The advantage of this approach is you only need to geocode the information once and then store this, versus sending coding requests each time the viewport changes.
An alternate efficient way of displaying this kind of data may be to use google fusion tables. this greatly simplifies the integration of the data with the map.

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.

Same address Google Maps - any ideas how to facilitate?

So I am trying to think of a way to facilitate two things. It may end up being a two step process in the end but I was looking for input.
The first thing I need to do is accommodate locations with the same address. The two scenarios that come to mind are businesses that share a location and apartment buildings.
The second thing I need to accommodate is a business/nonprofit with no headquarters, just a town. Right now I just map them to the town center, but if multiple businesses have no headquarters I run into the first problem.
So I did some Googling and found a solution that involved having a list of locations alongside the map so you can click on them and the info window will pop up. This isn't a solution for me though.
What I was thinking of was using the location to map the first point. For the second and points after that moving the marker over .05 degrees or something marginal so that the marker shows up. The inherent problem with that is that what happens if 12 Main Street turns into 13 Main Street?
So any thoughts on what I could do?
Thanks
Levi
There's an extension by Martin Pearman called ClusterMarker that detects any groups of two or more markers whose icons visually intersect when displayed. Each group of intersecting markers is then replaced with a single cluster marker that looks different. The cluster marker, when clicked, simply centres and zooms the map in on the markers whose icons previously intersected.
A more advanced approach to this problem might be SQL - same address = same coordinates...
GROUP BY or HAVING COUNT > 1 ... would let you create multi-record coordinates.
In fact - before you can cluster client-side, you need to send out the data first, which means transferring much more than required in this case, which results in higher loading times and higher RAM utilization client-side ...plus all the useless JS processing of the clusterer.
Client-side clustering is only recommend when the coordinates are close to each other, but not when they are absolutely identical.
Think about it...