admin管理员组文章数量:1423992
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.
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.
Share Improve this question edited Feb 15, 2012 at 16:00 jargetz asked Feb 15, 2012 at 15:43 jargetzjargetz 6249 silver badges16 bronze badges 3- 2 Here is how we solved it: I took the "encoded_polyline" field and sent it to our backend. If I needed to process the points on the backend, I used a version of the google polyline decoding algorithm that I found on line and porting to ruby (or whatever language you are using). Here's a python version I found. If you need to display the polyline on the front end you send the polyline up to the front end and use the Google Geometry Tool to decode it. – jargetz Commented Feb 5, 2013 at 1:59
- 1 Of course the downside to this is it only displays the route as a polyline, so if you want to have waypoints, you'll have to store those as well. And if you want to make the route editable then you are out of luck, you'll have to just request a new set of directions. – jargetz Commented Feb 5, 2013 at 2:00
-
If you have markers with waypoints then you can just store
waypoints list
(ormarkers list
withstart
-end
point) sequence wise into thedatabase
and then retive whenver require with the same sequence and pass to the directionrender with start and end point. It will draw again route on map. – bharat Commented Nov 21, 2016 at 10:13
2 Answers
Reset to default 2I 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?
Take a look at www.mapmyrun. they are using the google maps api and they are certainly persisting the data. However, its unlikely they use the free API.
本文标签: javascriptStoring complete Google Maps routeStack Overflow
版权声明:本文标题:javascript - Storing complete Google Maps route - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744713923a2621289.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论