样品JSON数据(从评论):为什么标记不在地图上正确地将移动
[{"id":"280","id_vehicle":"VL0847810531","lat":"30.0761","longi":"1.01981","speed":"144","time":"2014-12-03 12:07:23"},{"id":"202","id_vehicle":"VL0645210631","lat":"34.7344","longi":"7.32019","speed":"78","time":"2014-12-03 11:55:44"}]
function updateLocations(jsonData)
{
for (i=0 ;i< jsonData.length; i++) //for all vehicles
{
var id_vehicle = jsonData[i]["id_vehicle"];
var lat = jsonData[i]["lat"];
var lng = jsonData[i]["longi"];
var speed = jsonData[i]["speed"];
var str_time = jsonData[i]["time"];
/************************update list*******************************/
var state_icon, marker_icon, state;
var time = moment(str_time);
var last_10_Min = moment().subtract({minutes: 60 + 10});
if(time.isBefore(last_10_Min)) //if before 10 last minutes
{
state_icon = INACTIVE_IMG;
marker_icon = INACTIVE_VEHICLE;
state = "INACTIVE";
}
else //if befor
{
if(jsonData[i]["speed"] > 10) //if > 2 km/h then running
{
state_icon = RUN_IMG;
marker_icon = RUN_VEHICLE;
state = "RUN";
}
else
{
state_icon = STOP_IMG;
marker_icon = STOP_VEHICLE;
state = "STOP";
}
}
$("#state_img_"+id_vehicle).attr("src", state_icon);
$("#state_img_"+id_vehicle).attr('state',state);
$("#select_"+id_vehicle).attr("disabled" , false); // enable selection
/************************update location info*******************************/
var locationInfo = new Array();
img = "<img src=" + state_icon + " width='16' height='16' >";
locationInfo.push("Etat : " + state + " " + img + "<br>");
locationInfo.push("Latitude : " + lat + "<br>");
locationInfo.push("Longitude : " + lng + "<br>");
locationInfo.push("Vitess: " + speed + " klm/h<br>");
locationInfo.push("Temps : " + str_time + "<br>");
$("#info_location_" +id_vehicle).html(locationInfo.join(""));
/*****************update vehicles on map *************/
try {
cBox = $("#select_"+id_vehicle);
if(cBox.is(':checked')) //update selected only
{
//get marker index
var id_map = cBox.attr("id_map");
//change title
title = "Latitude: "+ lat + "\nLongitude: " + lng + "\nSpeed: " + speed + "\nTime: " + str_time;
arrayMarker[id_map].setTitle(title); //update title
arrayMarker[id_map].setIcon(marker_icon);
//move marker
arrayMarker[id_map].setPosition(new google.maps.LatLng(parseFloat(lat),parseFloat(lng)));
}
}catch(error){};
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
我的问题是,为什么whene执行该功能(更新位置)在地图上只是最前一页车辆正确地移动,其他更新(标题,图标...)但不动?
我注意到,他们移动并快速返回到原来的位置。
感谢您的任何建议。
你能举出一个JSON数据的例子吗?在3个位置中只有2个 – 2014-12-03 12:51:37
[{“id”:“280”,“id_vehicle”:“VL0847810531”,“lat”:“30.0761”,“longi”:“1.01981”,“速度”:“144”,“时间“:”2014-12-03 12:07:23“},{”id“:”202“,”id_vehicle“:”VL0645210631“,”lat“:”34.7344“,”longi“:”7.32019“速度“:”78“,”时间“:”2014-12-03 11:55:44“}] – 2014-12-03 13:33:05
请不要在评论中张贴代码,更新您的问题及相关信息。这次我为你做了这个。 – geocodezip 2014-12-03 13:54:57