Note that there are some explanatory texts on larger screens.

plurals
  1. POStoring complete Google Maps route
    text
    copied!<p>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 <a href="http://code.google.com/apis/maps/documentation/javascript/reference.html#DirectionsResult" rel="noreferrer">DirectionsResult</a> 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.</p> <p>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 <a href="http://code.google.com/apis/maps/documentation/javascript/reference.html#DirectionsRenderer" rel="noreferrer">DirectionsRenderer</a> object which will render the directions on the map. This approach has three problems:</p> <p>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.</p> <p>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.</p> <p>3) The object can be huge, one route I serialized was over 64KB. </p> <p>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.</p> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload