Reputation: 2493
I'm using Google Maps Javascript API V3 in my project. I want to move a marker from one postion to another position animately. I can update a mark's postion by
marker.setPosition(newPosition)
but how to smoothly move the marker?
Upvotes: 1
Views: 112
Reputation: 45111
var startPos, curPos, endPos, delta; // set these values
var interval;
curPos = startPos;
function move() {
marker.setPosition(curPos);
if ( curPos < endPos ) {
if ( curPos + delta > endPos ) curPos = endPos - curPos;
else curPos += delta;
setTimeout(move, interval);
}
}
move();
curPos
, startPos
endPos
, and delta
are instances of google.maps.LatLng
Upvotes: 2