简体   繁体   中英

add marker on specific distance in route in google map v2/v3

I want to create a webpage and use google map v2/v3 javascript api to create folowing functionality...

I want to add some markers on predefined route (no straight line) between two cities.

this new marker should be added on specific distance provided by user.

I searched lot online but i cant find a demo or blog to demonstrate this type of functionality...

please help me if anyone already went through this

Firstly definitely you want to use API 3, not API 2, which has been deprecated since May 2010.

There's two ways I think you could tackle this.
One would be to plot your markers along the route, and draw a Polyline between each of them. This is simple to setup, but would basically just draw straight (or geodesic curved) lines between the markers. If you want the route to actually follow a road for instance, you'd need to plot marker points for all the twists and turns of that road.

The other would be to use the DirectionsService to render the directions between your two cities, and use Waypoints to specify the markers in between that you want the directions to pass through. I think this would be better.

Here's an example of what that might be like: http://code.google.com/apis/maps/documentation/javascript/examples/directions-waypoints.html

And here's the Google tutorial on how to build it: http://code.google.com/apis/maps/documentation/javascript/services.html#Waypoints

For my money, the best tutorials are on the Google site anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM