I wish that a marker bounces for a few seconds and eventually stops automatically.. I am trying this code :
1. globalMarkers[i].setAnimation(google.maps.Animation.BOUNCE);
2. setTimeout(function() {
3. globalMarkers[i].setAnimation(null)
4. }, 3000);
but for some reason, line 1 executes (hence marker will start bouncing) but the 3rd line returns the following error:
Uncaught TypeError: Cannot call method 'setAnimation' of undefined
(anonymous function)
Any ideas what it could be?
This works fine (with a single global marker object)
My guess is that you’re interating, and your setTimeout i is not in scope. Try this instead:
There are some more creative solutions here:
Javascript how to use setTimeout on an iterative list operation?