Welcome to OStack Knowledge Sharing 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...