I have written a small application for a handheld device using JavaScript and Google Maps API's, now II need to move my marker icon anywhere on the map along a route using a timer function. I have a man icon and I need to move it automatically on the map. How can I do this?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
Hope this will help you here is a button and when you click on them marker move from source to destination route. setRoutes method is use for set the route of marker.
Make route after setting them.
At last we call start animation function
You can be found full code on GeekOnJava blog and copy that code and run them and output on youtube.
Unfortunately, there is no automatic-marker-movement function in the official GMaps collection.
However, if you have a GRoute, that would mean you have a set of points. To loop through the route steps, you could use something like this:
Of course, you'll probably want to do this asynchronously using the timers:
For even smoother movement, you could interpolate the points from those you already have.
It doesn't move something automatically, but you should check out the Google Drive experiment by phatfusion. Looking at the code might help you out.
A pretty cool example is here:
http://www.kmcgraphics.com/google/
Here is my solution that works with the v3 API. This animates the marker not with a fixed velocity, but based on the calculated route duration. There is a speed factor, so for example you can drive through the route 10x faster than in reality.
I've tried to do it as simple as possible. Feel free to use it.
Usage: