Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing complete Google Maps route

I want to be able to easily store and redisplay a Google Maps Directions Route on a Google Map. Let's say from point A to B, the DirectionsResult object from Google has 100 points along the route, I want to be able to store this route and guarantee the next time I paint it the directions will go through all of these points.

The way I have seen people trying to do it is to serialize the entire DirectionsResult object and store it in a database. Then when we want to redraw the route, send the string back up, JSON.Parse it, and then attempt to feed it to a DirectionsRenderer object which will render the directions on the map. This approach has three problems:

1) You lose type information during the serialization process, and since Google minnifies the objects, you aren't able to use class functions to get these values out of the object reliably. You need to first use data accessor functions to build 'place holder' objects when initially serializing the object, then rebuild the Google Maps objects when later parsing the serialized string.

2) It's legally dubious. The Google Maps TOS says you aren't supposed to store data permanently and it seems from other posts this approach violates it.

3) The object can be huge, one route I serialized was over 64KB.

I also thought about trying to store a few points from the path and then rebuilding it using Waypoints. This sort of works but you can only have at most 8 points for the free API, so this doesn't guarantee much accuracy beyond those 8 points. Furthermore, it then paints the waypoint markers along the route which I think could confuse the user.

Is there an accepted way to store exact routes from Google Maps, or are the API and TOS purposefully designed to prevent this? Thanks for the help.

like image 479
jargetz Avatar asked Feb 15 '12 15:02

jargetz


1 Answers

I believe this is legally dubious. In fact it almost certainly contravenes the Terms of Service. As you point out, it's permanent storage for purposes other than improving performance (contrary to 10.1.3(b)); but it's also intended to show directions without getting them via the API (contrary to 10.1.1(a)). The fact that Google have not made it easy means that they have not authorised this use case. In fact the TOS and the API are designed to make storage like this difficult if not impossible.

Would it not be acceptable to store start and end points and let the API work out the route when you want to display it again?

like image 110
Andrew Leach Avatar answered Sep 28 '22 08:09

Andrew Leach