Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

google maps api 3 - Add Markers Along a Route

I am trying to create several markers along a route from google maps directions. I have already looked into waypoints as an option but based on my understanding of the documentation on it, it creates the route from point A to point B and passes through the waypoints that you set in order to get from point A to point B. I don't want my route to be calculated based on predetermined waypoints. I want a predetermined start and end point, with my waypoints calculated based on a distance on the map. For instance, a marker created every so many miles along the route. Would waypoints do this? If so, any examples of where that has been done?

Any suggestions?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As Andrew told waypoints wouldn't do it.

You don't have predefined points for the route (like the example), so what you can do is:

A direction consists of points defined by route->overview_path, what defines the polyline for the route.

So you may walk this path, calculate the distance between two path-points using google.maps.geometry.spherical.computeDistanceBetween() and create the marker when the desired distance has been reached.

Here is an implementation of the suggestion: http://jsfiddle.net/doktormolle/eNzFb/


<edit>

Please Note: this answer is obsolete. You better use the built-in IconSequence instead.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...