I have to show vehicle movements in google map, so on click of of group i make ajax call it gets lat lng and some info of all vehicles then I place a marker on map. Here if vehicle moves for the next ajax call I get diff lat lng at that time I show transition effect to marker. this is giving me problem ,
Here is my callback function of Ajax,
function callBackFunction(http_request) {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
var rs = http_request.responseText;
//here rs is as follow in servlet fstring=fstring+lat+","+lng+"$"+vn+"@notsame@"+busImg+"@"+drvcdr+"#";
var SlNo=0;
var position="";
var busImg="";
clear_Icon();
while(rs.length)
{
lat=rs.substring(0,rs.indexOf(","));
lng=rs.substring(rs.indexOf(",")+1,rs.indexOf("$"));
vn=rs.substring(rs.indexOf("$")+1,rs.indexOf("@"));
rs=rs.substring(rs.indexOf("@")+1);
position=rs.substring(0,rs.indexOf("@"));
rs=rs.substring(rs.indexOf("@")+1);
busImg=rs.substring(0,rs.indexOf("@"));
rs=rs.substring(rs.indexOf("@")+1);
drvcdr=rs.substring(0,rs.indexOf("#"));
add_icon(lat,lng,SlNo,vn,position,busImg,drvcdr);
rs=rs.substring(rs.indexOf("#")+1);
SlNo++;
}
} else {
alert('ERR OR: AJAX request status = ' + http_request.status);
}
}
}
placing marker and transition effect,
function add_icon(lt, ln,n,vn,position,busImg,drvcdr) {
var point = new google.maps.LatLng( lt, ln);
//alert("Icon: "+busImg);
marker= createMarker(point,n,vn,position,busImg,drvcdr);
alert("After Marker placed:"+point.lat()+" "+point.lng());
transitionnn(point);
}
var gmarkers = [];
function createMarker(point, number,vn,position,busImg,drvcdr) {
var angleDegrees = 150;
var marker = new google.maps.Marker({
position: point,
map: map,
raiseOnDrag: true,
icon:busImg,
// animation: google.maps.Animation.DROP,
draggable: false,
zIndex: number,
id:vn,
drvcddr:drvcdr
});
var html = number;
var infowindow = new google.maps.InfoWindow({
content: 'Latitude: ' + point.lat() +
'<br>Longitude: ' + point.lng() + '<br>BusNo : '+ marker.get("id")+ '<br>DrivrConductor : '+ marker.get("drvcddr"),
maxwidth: 1000
});
google.maps.event.addListener(marker, 'click', function() {
//map.setZoom(15);
map.setCenter(marker.getPosition());
infowindow.open(map,marker);
});
gmarkers.push(marker);
return marker;
};
function transitionnn(point)
{
var result = [point.lat(), point.lng()];
transition(result);
}
var numDeltas = 100;
var delay = 100; //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);
}
}
The problem is , in map I get markers but not in exact position and transition effect also not showing currectly. I dont know where I am going wrong can anyone help me to solve this . THank you.
I think this is basically the effect you want.
What I do: 4 cars start from Brussels; each time you click on the button, you get the next points. Each marker transitions to its new spot.
The data should come from some DB (or so); I just use 3 sets of location (for each car)
Notice: you don't use jQuery. So I made (kind of) a minimal version of $.ajax with raw javascript
ajax_json.php
index.php