I am using this Script to move the Google Map marker from 1 place to another source Extend Google Maps marker to animate smoothly on update?
As per my logic here the Difference between the Previous & the Current Location is calculated & divided by a number (eg 100) & adding the result to the Previous Location for 100 times to reach the Current Location.
But when I change the Value of steps (Num Deltas) as given below from 100 to any other Number for Eg 4 & make the Loop run 4 times the Location of the Marker after that is different from the Current Location. Can any one plaese suggest me the Importance of using the No. of Steps (Num Deltas) as 100 & not any other Number`
var latlng = new google.maps.LatLng(position[0], position[1]);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
marker = new google.maps.Marker({
position: latlng,
map: map,
title: "Your current location!"
});
google.maps.event.addListener(map, 'click', function(me) {
var result = [me.latLng.lat(), me.latLng.lng()];
transition(result);
});
}
var numDeltas = 100;
var delay = 10; //milliseconds
var i = 0;
var deltaLat;
var deltaLng;
function transition(result){
i = 0;
deltaLat = (result[0] - position[0])/numDeltas;
deltaLng = (result[1] - position[1])/numDeltas;
moveMarker();
}
function moveMarker(){
position[0] += deltaLat;
position[1] += deltaLng;
var latlng = new google.maps.LatLng(position[0], position[1]);
marker.setPosition(latlng);
if(i!=numDeltas){
i++;
setTimeout(moveMarker, delay);
}
}
Here is a jsFiddle of the code working: http://jsfiddle.net/rcravens/RFHKd/13/