2014-12-03 82 views
-1

樣品JSON數據(從評論):爲什麼標記不在地圖上正確地將移動

[{"id":"280","id_vehicle":"VL0847810531","lat":"30.0761","longi":"1.01981","spee‌​d":"144","time":"2014-12-03 12:07:23"},{"id":"202","id_vehicle":"VL0645210631","lat":"34.7344","longi":"7.32‌​019","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執行該功能(更新位置)在地圖上只是最前一頁車輛正確地移動,其他更新(標題,圖標...)但不動?

我注意到,他們移動並快速返回到原來的位置。

感謝您的任何建議。

+1

你能舉出一個JSON數據的例子嗎?在3個位置中只有2個 – 2014-12-03 12:51:37

+0

[{「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

+2

請不要在評論中張貼代碼,更新您的問題及相關信息。這次我爲你做了這個。 – geocodezip 2014-12-03 13:54:57

回答

0

finaly我發現問題,這是這裏:

變種標記=新MarkerWithLabel({......});

arrayMarker [id_map] = marker; //放標誌物arrayMarker在indexMarker位置

錯誤發生whene我填寫使用MarkerWithLabel(3TH LIB)我arrayMarker

whene更改爲純google.maps.Marker它正確地將工作:

var marker = new google.maps.Marker({......}); arrayMarker [id_map] = marker;

+1

除了您之外,沒有任何人可以知道,您沒有發佈任何引用MarkerWithLabel的代碼。 – geocodezip 2014-12-03 14:52:17

+0

還有其他擴展原生標記的其他庫嗎? – 2014-12-04 09:55:23

相關問題