var mapType=2;
var baidMap;
var idsData;
var markers =[];
var bzMarkers =[];
var namekg = true;
var newdata;
var mapOptions;
var yanchiAl;
var baidubool = false;
var MenuNum=[1,2,3,4,5,6,7,8,9,10,11,12,13,14];
var bzMarkersById=[];
var linshiMarker = new Object();
var baocunLatlng;
function googleToBaidu(glng,glat) {
	
	var x_pi = 3.14159265358979324 * 3000.0 / 180.0;
	//alert(x_pi);
	
	var x = glng, y = glat;
	var z =Math.sqrt(x * x + y * y) + 0.00002 *Math.sin(y * x_pi);
	var theta =Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
	var lng = z *  Math.cos(theta) + 0.0065;
	var lat = z *  Math.sin(theta) + 0.006;
	var myLatlng = new BMap.Point(lng,lat);
	
	return myLatlng;
	
}
function baiduToGoogle(blng,blat) {

	var x_pi = 3.14159265358979324 * 3000.0 / 180.0;
	var lng=blng;
	var lat=blat;
	var x = lng - 0.0065, y = lat - 0.006;
	var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
	var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
	lng = z * Math.cos(theta);
	lat = z * Math.sin(theta);
	var obj=new Object();
	obj.lng=lng;
	obj.lat=lat;
	return obj;
}

function cutoverMap() {
	 	if(mapType==1){
			mapType=2
		}else{
			mapType=1
		}
		var checkbox1 = document.getElementsByName("checkbox1");
		if(checkbox1[0].checked){
			 checkbox1[0].checked = "";
	    }
		
		var bzcheckbox = document.getElementsByName("bzcheckbox");
		if(bzcheckbox[0].checked){
			 bzcheckbox[0].checked = "";
	    }
	 

	 memoryStatus(true);
 
	 //alert(getUserStatus().lat+","+getUserStatus().lng+","+getUserStatus().zoom);
	 var  myselect=document.getElementById("select");
	 var index=myselect.selectedIndex ;
	 mapType=myselect.options[index].value;
	 
	 initTool();//切换地图时初始化工具
	 /*
	 if(isLargeData==true){
		 idsData="thresholds";
	 }
	 */
	 if(1==mapType){
		 	 markers.length=0;
		 	 bzMarkers.length=0;
			 baiduMap(idsData,false);
			 showMarkerBaidu(markerObject.markerJson);
			 addMenu();
			 shieldFence();
	 }else{
		 	 vehicles.length=0;
			 googleMap();
			 //点击地图时关闭已经打开的弹出框
			 mapclickEvent();
			  //添加标注菜单
			 addMarkerMenu();
			  //添加所有标注  
			 addAllMarker();
			 
			 electronicFence.tree.init();
			 
			 openFence();

	 }
	
	 initMarkerisShow();
	 
	 /*
	 var checkbox1 = document.getElementsByName("checkbox1");
	 if(checkbox1[0].checked){
		 checkbox1[0].checked = "";
     }*/
     /*
	 var bzcheckbox = document.getElementsByName("bzcheckbox");
	 if(bzcheckbox[0].checked){
		 bzcheckbox[0].checked = "";
     }*/
	 //al();
	 if(namekg == false){
		 namekg = true;
	 }
	
	 if(findbsCookie("isShowCarName")==true){
			$("#isShowCarName").attr("checked",true);
			namekg = true;
			showCarName();
	 }
	 
	 //namekg = false;
	 //showCarName();
	 /*
	 ExliveMap.setMap(mapType);//设置地图类型
	 SheFang.show();//显示所有设防设备设防区域
	 */
}
function getAreaNELatLngBaidu(lat_,lng_,len_){
	var dlat = len_/111.0/1000.0;
	var dlng = len_/85.567/1000.0;
	$("#rigthlat").val(lat_-dlat);
	$("#rigthlng").val(lng_+dlng);
	return new BMap.Point(lng_+dlng,lat_-dlat);
}
function getAreaSWLatlngBaidu(lat_,lng_,len_){
	var dlat = len_/111.0/1000.0;
	var dlng = len_/85.567/1000.0;
	$("#leftlat").val(lat_+dlat);
	$("#leftlng").val(lng_-dlng);
	return new BMap.Point(lng_-dlng,lat_+dlat);
}
var oldPolygon = new BMap.Polygon();
function addMarkerBaidu(pStart,pEnd){
	
	oldPolygon.setPath([googleToBaidu(pStart.lng(),pStart.lat()),googleToBaidu(pEnd.lng(),pStart.lat()), googleToBaidu(pEnd.lng(),pEnd.lat()),googleToBaidu(pStart.lng(),pEnd.lat())]);
	oldPolygon.setStrokeColor("blue");
	oldPolygon.setFillColor("blue");
	oldPolygon.setStrokeWeight(2);
	oldPolygon.setStrokeOpacity(0.5);
	baidMap.addOverlay(oldPolygon);
	
}

function updateMarkerBaidu(id,pStart,pEnd){
	
	for(i=0;i<bzMarkers.length;i++){
		if(bzMarkers[i].id==id){
			
			bzMarkers[i].polygon.setPath([googleToBaidu(pStart.lng,pStart.lat),googleToBaidu(pEnd.lng,pStart.lat),googleToBaidu(pEnd.lng,pEnd.lat),googleToBaidu(pStart.lng,pEnd.lat)]);
			
			break;
		}
	}
}
function updateBzMarkers(markersJson){
	for(var i=0;i<bzMarkers.length;i++){
			if(bzMarkers[i].id==markersJson.data[0].id){
				var blat;
				var blng;
				
					blat=markersJson.data[0].lat2;
					blng=markersJson.data[0].lng2;
				
				var myIcon = new BMap.Icon(markersJson.data[0].icon, new BMap.Size(35,35));
				var html="<div style='font-weight:normal;'><b>名称：</b>"+markersJson.data[0].title+"</br>"
				+"<b>描述：</b>"+markersJson.data[0].text+"</br>"
				+"<b>经度：</b>"+blat+"</br>"
				+"<b>纬度：</b>"+blng+"</br>";
				var htm="<a href='javascript:openUpdateMarkerWin("+markersJson.data[0].id+");'><font color='#0000FF'>修改</font></a></div>";//<a href='javascript:deleteMarker("+markersJson.data[0].id+");'><font color='#0000FF'>删除</font></a> 
				if(markersJson.data[0].competence==1){
					html=html+htm;
				}else{
					html=html+"</div>";
				}
				bzMarkers[i].marker.setIcon(myIcon);
				bzMarkers[i].label.setContent(markersJson.data[0].title);
				bzMarkers[i].infowindow.setContent(html);
				//var pStart = new BMap.Point(markersJson.data[0].userMarkerArea.leftLon,markersJson.data[0].userMarkerArea.leftLat);
				//var pEnd = new BMap.Point(markersJson.data[0].userMarkerArea.rightLon,markersJson.data[0].userMarkerArea.rightLat);
				//bzMarkers[i].polygon.setPath([new BMap.Point(pStart.lng,pStart.lat),new BMap.Point(pEnd.lng,pStart.lat), new BMap.Point(pEnd.lng,pEnd.lat),new BMap.Point(pStart.lng,pEnd.lat)]);
				
				break;
			}
		}
}
function delMarkerBaidu(id){
    for(i=0;i<bzMarkers.length;i++){
		if(bzMarkers[i].id==id){
			baidMap.removeOverlay(bzMarkers[i].label);
			baidMap.removeOverlay(bzMarkers[i].marker);
			baidMap.removeOverlay(bzMarkers[i].infowindow);
			baidMap.removeOverlay(bzMarkers[i].polygon);
			bzMarkers.remove(i);
			break;
		}
	}
	for(var i=0;i<markerObject.markerJson.data.length;i++){
   	  if(id==markerObject.markerJson.data[i].id){
				markerObject.markerJson.data.remove(i);
				break;
		  }
    }
	markerObject.markerJson.totalcount = markerObject.markerJson.data.length;
	
	
}
function openMarkerBaidu(id){
	for(i=0;i<bzMarkers.length;i++){
		if(bzMarkers[i].id==id){
			bzMarkers[i].marker.openInfoWindow(bzMarkers[i].infowindow);
			baidMap.centerAndZoom(bzMarkers[i].latlng, 15);
			break;
		}
	}
}
function updateMarkerIsShow(id,isShow,isAll){
	if(isAll){
		for(i=0;i<bzMarkers.length;i++){
				bzMarkers[i].isShow = isShow;
		}
	}else{
		for(i=0;i<bzMarkers.length;i++){
			if(bzMarkers[i].id==id){
				bzMarkers[i].isShow = isShow;
				break;
			}
		}
	}
	
}
function showMarkersBaidu(id,bool){
	var bzcheckbox = document.getElementsByName("bzcheckbox");
	if(bool){
		for(i=0;i<bzMarkers.length;i++){
				baidMap.addOverlay(bzMarkers[i].marker);
				baidMap.addOverlay(bzMarkers[i].polygon);
				 if(bzcheckbox[0].checked){
					 baidMap.addOverlay(bzMarkers[i].label);
			     }
		}
	}else{
		for(i=0;i<bzMarkers.length;i++){
			if(bzMarkers[i].id==id){
				
				baidMap.addOverlay(bzMarkers[i].marker);
				baidMap.addOverlay(bzMarkers[i].polygon);
				if(bzcheckbox[0].checked){
					 baidMap.addOverlay(bzMarkers[i].label);
			     }
			}
		}
	}
	
}
function hideMarkersBaidu(id,bool){
	if(bool){
		for(i=0;i<bzMarkers.length;i++){
				baidMap.removeOverlay(bzMarkers[i].marker);
				baidMap.removeOverlay(bzMarkers[i].polygon);
				baidMap.removeOverlay(bzMarkers[i].label); 
		}
	}else{
		for(i=0;i<bzMarkers.length;i++){
			if(bzMarkers[i].id==id){
				baidMap.removeOverlay(bzMarkers[i].marker);
				baidMap.removeOverlay(bzMarkers[i].polygon);
				baidMap.removeOverlay(bzMarkers[i].label); 
			}
		}
	}
	
}
function baocunMarker(id){
	
	var latlng= baiduToGoogle(baocunLatlng.lng,baocunLatlng.lat);
	
	var pStart = getAreaNELatLng(latlng.lat,latlng.lng,bzMarkersById[id].markerRadius);

	var pEnd = getAreaSWLatlng(latlng.lat,latlng.lng,bzMarkersById[id].markerRadius);
	
	$.ajax({
        type: "POST",
        dataType: "json",
        async:true,
        url: "json/markerAction_addOrUpdateUserMarker.action",
        data:{"id":id,"lng":latlng.lat,"lat":latlng.lng,"leftLat":pEnd.lat(),"leftLon":pEnd.lng(),"rightLat":pStart.lat(),"rightLon":pStart.lng(),"title":bzMarkersById[id].obj.title,"text":bzMarkersById[id].obj.text,"icon":bzMarkersById[id].obj.icon,"groupid":bzMarkersById[id].obj.groupid,"radius":bzMarkersById[id].markerRadius,"bzType":bzMarkersById[id].bzType,"customerNum":bzMarkersById[id].markcode,"mapType":2},	        
        success: function(json) {		         
	         if (json.flag==true) {
	        	 /*
		  		_marker.lat=json.data[0].lng2;
		  		_marker.lng=json.data[0].lat2;
			  	_marker.areaRadius=json.data[0].userMarkerArea.markerRadius;
	      		$("#moveMarkerBtn").hide();
	      		*/
	      		quxiaoMarker.latlng=null;
             }else{
             	$("#updatePositionMsg").val("*"+json.msg);
             	
             }
        },
        error: function() {}
   });	
}
function quxiaoMarker(id){
	
	bzMarkersById[id].marker.setPosition(quxiaoMarker.latlng);
	if(bzMarkersById[id].markerRadius != 0){
		var pStart = getAreaNELatLngBaidu(quxiaoMarker.latlng.lat,quxiaoMarker.latlng.lng,bzMarkersById[id].markerRadius);
			
		var pEnd = getAreaSWLatlngBaidu(quxiaoMarker.latlng.lat,quxiaoMarker.latlng.lng,bzMarkersById[id].markerRadius);
		
		bzMarkersById[id].polygon.setPath([ new BMap.Point(pStart.lng,pStart.lat), new BMap.Point(pEnd.lng,pStart.lat), new BMap.Point(pEnd.lng,pEnd.lat), new BMap.Point(pStart.lng,pEnd.lat)]);
		
		
	}
	quxiaoMarker.latlng=null;
}
function showMarkerBaidu(markersJson){
	
	if(markersJson == ""){
		return;
	}
	for(var i=0;i<markersJson.data.length;i++){
		(function(x){
			var myLatlng = googleToBaidu(markersJson.data[i].lat2,markersJson.data[i].lng2);
			var myIcon = new BMap.Icon(markersJson.data[i].icon, new BMap.Size(35,35));
			var marker = new BMap.Marker(
					myLatlng
					,{icon:myIcon}
			);  // 创建标注
			//baidMap.addOverlay(marker);
			marker.enableDragging();
			marker.setTitle(markersJson.data[x].id);
			var opts = {
			  position : myLatlng,    // 指定文本标注所在的地理位置
			  offset   : new BMap.Size(15, -10)    //设置文本偏移量
			 
			}
			var label = new BMap.Label(markersJson.data[i].title, opts);  // 创建文本标注对象
			label.setStyle({
				 color : "#000000",
				 backgroundColor : "#f5fcb8",
				 borderColor : "#000000",
				 fontSize : "12px",
				 height : "16px",
				 lineHeight : "16px",
				 fontWeight:"bold",
				 fontFamily:""
			});
			//baidMap.addOverlay(label); 
			//创建信息窗口
			var html="<div style='font-weight:normal;'><b>名称：</b>"+markersJson.data[i].title+"</br>"
			+"<b>描述：</b>"+markersJson.data[i].text+"</br>"
			+"<b>经度：</b>"+markersJson.data[i].lat2+"</br>"
			+"<b>纬度：</b>"+markersJson.data[i].lng2+"</br>";
			
			var htm="<a href='javascript:openUpdateMarkerWin("+markersJson.data[i].id+");'><font color='#0000FF'>修改</font></a></div>";// | <a href='javascript:deleteMarker("+markersJson.data[i].id+");' ><font color='#0000FF'>删除</font></a> 
			if(markersJson.data[i].competence==1){
				html=html+htm;
			}else{
				html=html+"</div>";
			}
			var infoWindow = new BMap.InfoWindow(html);
			
			marker.addEventListener("dragging",function(e){
				if(linshiMarker.latlng == null){
					//alert(quxiaoMarker.latlng.lat);
					quxiaoMarker.latlng=bzMarkersById[e.target.getTitle()].latlng;
					quxiaoMarker.platlng=bzMarkersById[e.target.getTitle()].polygon.getPath();
				}
				baocunLatlng = e.point;
				var html="<div style='font-weight:normal;'><b>名称：</b>"+bzMarkersById[e.target.getTitle()].title+"</br>"
				+"<b>描述：</b>"+bzMarkersById[e.target.getTitle()].text+"</br>"
				+"<b>经度：</b>"+e.point.lat+"</br>"
				+"<b>纬度：</b>"+e.point.lng+"</br>";
				
				var htm="<a href='javascript:openUpdateMarkerWin("+e.target.getTitle()+");'><font color='#0000FF'>修改 |</font></a><a href='javascript:baocunMarker("+e.target.getTitle()+");'><font color='#0000FF'>保存 | </font></a><a href='javascript:quxiaoMarker("+e.target.getTitle()+");'><font color='#0000FF'>取消</font></a></div>";// | <a href='javascript:deleteMarker("+markersJson.data[i].id+");' ><font color='#0000FF'>删除</font></a> 
				if(bzMarkersById[e.target.getTitle()].competence==1){
					html=html+htm;
				}else{
					html=html+"<a href='javascript:baocunMarker("+e.target.getTitle()+");'><font color='#0000FF'>保存 | </font></a><a href='javascript:quxiaoMarker("+e.target.getTitle()+");'><font color='#0000FF'>取消</font></a></div>";
				}
				infoWindow.setContent(html);
				if(bzMarkersById[e.target.getTitle()].markerRadius != 0){
				var pStart = getAreaNELatLngBaidu(e.point.lat,e.point.lng,bzMarkersById[e.target.getTitle()].markerRadius);
					
				var pEnd = getAreaSWLatlngBaidu(e.point.lat,e.point.lng,bzMarkersById[e.target.getTitle()].markerRadius);
				
				bzMarkersById[e.target.getTitle()].polygon.setPath([ new BMap.Point(pStart.lng,pStart.lat), new BMap.Point(pEnd.lng,pStart.lat), new BMap.Point(pEnd.lng,pEnd.lat), new BMap.Point(pStart.lng,pEnd.lat)]);
				
				
				}
				this.openInfoWindow(infoWindow);
			});
			marker.addEventListener("click", function(){this.openInfoWindow(infoWindow);});
			var pStart;
			var pEnd;
			if(markersJson.data[i].userMarkerArea == null || markersJson.data[i].userMarkerArea ==""){
				var pStart = new BMap.Point(0,0);
				var pEnd = new BMap.Point(0,0);
			}else{
				
					var pStart = new BMap.Point(markersJson.data[i].userMarkerArea.leftLon,markersJson.data[i].userMarkerArea.leftLat);
					var pEnd = new BMap.Point(markersJson.data[i].userMarkerArea.rightLon,markersJson.data[i].userMarkerArea.rightLat);
					
			}
			var polygon = new BMap.Polygon([
	              googleToBaidu(pStart.lng,pStart.lat),
	              googleToBaidu(pEnd.lng,pStart.lat),
	              googleToBaidu(pEnd.lng,pEnd.lat),
	              googleToBaidu(pStart.lng,pEnd.lat)
	          ], {strokeColor:"blue",fillColor:"blue", strokeWeight:2, strokeOpacity:0.5});
			//baidMap.addOverlay(polygon);
			
			markerManage = new Object();
			markerManage.id = markersJson.data[i].id;
			markerManage.title = markersJson.data[i].title;
			markerManage.label = label;
			markerManage.text = markersJson.data[i].text;	
			markerManage.marker = marker;	
			markerManage.polygon = polygon;
			markerManage.icon = markersJson.data[i].icon;
			markerManage.infowindow = infoWindow;
			markerManage.latlng = myLatlng;
			markerManage.isShow = false;
			markerManage.obj=markersJson.data[i];
			markerManage.competence = markersJson.data[i].competence;
			if( markersJson.data[i].userMarkerArea != null){
				markerManage.markerRadius=markersJson.data[i].userMarkerArea.markerRadius;
			}else{
				markerManage.markerRadius=0;
			}
			
			bzMarkers.push(markerManage);
			bzMarkersById[markerManage.id]=markerManage;
			
		})(i);
    }	
}
var strNum =0;
function addMarkers(iNum,j){
	for(var i=iNum;i<j;i++){
		(function(tx){
			if(carList.data[tx] != "" && carList.data[tx] !=null){
					var x_pi = 3.14159265358979324 * 3000.0 / 180.0;
					var x = carList.data[tx].positionLast.lng, y = carList.data[tx].positionLast.lat;
					var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
					var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
					var lng = z *  Math.cos(theta) + 0.0065;
					var lat = z *  Math.sin(theta) + 0.006;
					var myLatlng = new BMap.Point(lng,lat);
					var s = 10;
					var condition=carList.data[tx].positionLast.state2;
				  	var sp = parseInt(carList.data[tx].positionLast.speed);
				  	if (condition != null) {
					if (condition.indexOf("不在线")>=0 || condition.indexOf("掉线")>=0)
						s = 2;
					else {
						if (condition.indexOf("速报警")>=0)
							s = 4;
						else if (condition.indexOf("报警")>=0)
							s = 3;
						else if (sp > 0.5)
							s = 0;
						else
							s = 1;
					}
					if (s != 4 && s != 3 && condition.indexOf("停车")>=0
							&& !condition.indexOf("不在线")>= 0)
						{
							if(condition.indexOf("停车超时")>=0){
								s = 5;	
							}else{
								s = 6;
							}
						}
				}else{
					if (sp > 0.5)
						s = 0;
					else
						s = 1;
				}
				  	if( carList.data[tx].positionLast.av == 0 ){
						s=7;
					}
				var newtime = new Date().getTime();
							var ttime =carList.data[tx].positionLast.recvtime.replace("-","/");
							ttime=ttime.replace("-","/");
							ttime=ttime.replace("T"," ");
							var oldtime = new Date(ttime).getTime();
							if(newtime-oldtime > 600000){
								s=2;
							}
				
			  	var state =s;
			  	var pngicon = "gpsonline/image/pic/"+carList.data[tx].icon+"/red_0.gif";
				if(state == 0) pngicon = "gpsonline/image/pic/"+carList.data[tx].icon+"/green_";
				else if(state == 1) pngicon = "gpsonline/image/pic/"+carList.data[tx].icon+"/red_";
				else if(state == 2) pngicon = "gpsonline/image/pic/"+carList.data[tx].icon+"/gray_";
				else if(state == 3) pngicon = "gpsonline/image/pic/"+carList.data[tx].icon+"/yellow_";
				else if(state == 4) pngicon = "gpsonline/image/pic/"+carList.data[tx].icon+"/pink_";
				else if(state == 5) pngicon = "gpsonline/image/pic/"+carList.data[tx].icon+"/stopalarm";
				else if(state == 7) pngicon = "gpsonline/image/pic/"+carList.data[tx].icon+"/blue_";
				else pngicon = "gpsonline/image/pic/"+carList.data[tx].icon+"/red_";
						 var direction="";
						 var t = parseInt(carList.data[tx].positionLast.direct);
						  if(t>27 && t<=72){
						  		if(state == 5){
						  			var image=".gif";
						  		}else{
						  			var image="45.gif";
						  		}
								direction="东北";
							}else if(t>72 && t<=117){
								if(state == 5){
						  			var image=".gif";
						  		}else{
						  			var image="90.gif";
						  		}
								
								direction="东";
							}
							else if(t>117 && t<=162){
								if(state == 5){
						  			var image=".gif";
						  		}else{
						  			var image="135.gif";
						  		}
								direction="东南";
							}
							else if(t>162 && t<=207){
								if(state == 5){
						  			var image=".gif";
						  		}else{
						  			var image="180.gif";
						  		}
								direction="南";
							}
							else if(t>207 && t<=252){
								if(state == 5){
						  			var image=".gif";
						  		}else{
						  			var image="225.gif";
						  		}
								direction="西南";
							}
							else if(t>252 && t<=297){
								if(state == 5){
						  			var image=".gif";
						  		}else{
						  			var image="270.gif";
						  		}
								direction="西";
							}
							else if(t>297 && t<=342){
								if(state == 5){
						  			var image=".gif";
						  		}else{
						  			var image="315.gif";
						  		}
								direction="西北";
							}
							else {
								if(state == 5){
						  			var image=".gif";
						  		}else{
						  			var image="0.gif";
						  		}
								direction="北";
							}
				
				
				
	      			var carname = encodeURI(encodeURI(carList.data[tx].vhcCode)); 
					
					var temp,temp1,temp2,temp3,temp4;
					if(carList.data[tx].positionLast.temperature != null && carList.data[tx].positionLast.temperature <=100){
						temp=carList.data[tx].positionLast.temperature +" ℃";
					}else{
						temp="无效";
					}
					if(carList.data[tx].positionLast.temp1 != null && carList.data[tx].positionLast.temp1 <=100){
						temp1=carList.data[tx].positionLast.temp1 +" ℃";
					}else{
						temp1="无效";
					}
					if(carList.data[tx].positionLast.temp2 != null && carList.data[tx].positionLast.temp2 <=100){
						temp2=carList.data[tx].positionLast.temp2 +" ℃";
					}else{
						temp2="无效";
					}
					if(carList.data[tx].positionLast.temp3 != null && carList.data[tx].positionLast.temp3 <=100){
						temp3=carList.data[tx].positionLast.temp3 +" ℃";
					}else{
						temp3="无效";
					}
					if(carList.data[tx].positionLast.temp4 != null && carList.data[tx].positionLast.temp4 <=100){
						temp4=carList.data[tx].positionLast.temp4 +" ℃";
					}else{
						temp4="无效";
					}
					
					var html="";
					if(alarmType=="Bus_client"){
						    html =	"<div id='app_"+carList.data[tx].id+"' style='font-weight:normal;'>"
						    +"<div id='app1_"+carList.data[tx].id+"'><b>设备名称：</b>"+carList.data[tx].vhcCode+"</br></div>"
						    +"<div id='app14_"+carList.data[tx].id+"'><b>备注：</b>"+carList.data[tx].remark+"</br></div>"
						    +"<div id='app11_"+carList.data[tx].id+"'><b>SIM卡号：</b>"+carList.data[tx].simCode+"</br></div>"
							+"<div id='app2_"+carList.data[tx].id+"'><b>服务器时间：</b>"+carList.data[tx].positionLast.recvtime+"</br></div>"
							+"<div id='app12_"+carList.data[tx].id+"'><b>GPS时间：</b>"+carList.data[tx].positionLast.gpstime+"</br></div>"
							+"<div id='app3_"+carList.data[tx].id+"'><b>速度：</b>"+carList.data[tx].positionLast.speed.toFixed(1)+"km/h </br></div>"
							+"<div id='app4_"+carList.data[tx].id+"'><b>方向：</b>"+direction+"</br></div>"
							+"<div id='app5_"+carList.data[tx].id+"'><b>温度：</b>"+temp+" | <b>温度1：</b>"+temp1+" | <b>温度2：</b>"+temp2+" | <b>温度3：</b>"+temp3+" | <b>温度4：</b>"+temp4+"</br></div>"
							+"<div id='app6_"+carList.data[tx].id+"'><b>油量：</b>"+carList.data[tx].positionLast.oilMN1+" L</br></div>"
							+"<div id='app7_"+carList.data[tx].id+"'><b>当日里程：</b>"+carList.data[tx].positionLast.distance+" km</br></div>"
							+"<div id='app8_"+carList.data[tx].id+"'><b>总里程：</b>"+carList.data[tx].positionLast.totalDistance+" km</br></div>"
							+"<div id='app9_"+carList.data[tx].id+"'><b>状态：</b>"+carList.data[tx].positionLast.state2+"</br></div>"
							+"<div id='app10_"+carList.data[tx].id+"'><b>位置：</b>"+carList.data[tx].positionLast.memo+"</br></div>"
							+"<div id='app13_"+carList.data[tx].id+"'><b>OBD数据：</b><a href='javascript:opobd("+carList.data[tx].id+");'><font color='#0000FF'>详细</font></a></br></div>"
							+"<a id='track_"+carList.data[tx].id+"' onclick='openTrackFrame(this,event)' href='javascript:;'><font color='#0000FF'>跟踪</font> | </a><a id='' onclick='voiceStar(\""+carList.data[tx].voiceCode+"\",\""+carList.data[tx].dataCode+"\")' href='javascript:;'><font color='#0000FF'>视频</font> | </a><a id='playback_"+carList.data[tx].id+"' onclick='openBackFrame(this,event);' href='javascript:;'><font color='#0000FF'>回放</font> | </a>  <a id='more_"+carList.data[tx].id+"' href='javascript:;' onclick=\"showSecondMenu(this,event);\"><font color='#0000FF'>更多▼</font></a></p></div></div>";
					}else{
						html =	"<div id='app_"+carList.data[tx].id+"' style='font-weight:normal;'>"
					    +"<div id='app1_"+carList.data[tx].id+"'><b>设备名称：</b>"+carList.data[tx].vhcCode+"</br></div>"
					    +"<div id='app14_"+carList.data[tx].id+"'><b>备注：</b>"+carList.data[tx].remark+"</br></div>"
					    +"<div id='app11_"+carList.data[tx].id+"'><b>SIM卡号：</b>"+carList.data[tx].simCode+"</br></div>"
						+"<div id='app2_"+carList.data[tx].id+"'><b>服务器时间：</b>"+carList.data[tx].positionLast.recvtime+"</br></div>"
						+"<div id='app12_"+carList.data[tx].id+"'><b>GPS时间：</b>"+carList.data[tx].positionLast.gpstime+"</br></div>"
						+"<div id='app3_"+carList.data[tx].id+"'><b>速度：</b>"+carList.data[tx].positionLast.speed.toFixed(1)+"km/h </br></div>"
						+"<div id='app4_"+carList.data[tx].id+"'><b>方向：</b>"+direction+"</br></div>"
						+"<div id='app5_"+carList.data[tx].id+"'><b>温度：</b>"+temp+" | <b>温度1：</b>"+temp1+" | <b>温度2：</b>"+temp2+" | <b>温度3：</b>"+temp3+" | <b>温度4：</b>"+temp4+"</br></div>"
						+"<div id='app6_"+carList.data[tx].id+"'><b>油量：</b>"+carList.data[tx].positionLast.oilMN1+" L</br></div>"
						+"<div id='app7_"+carList.data[tx].id+"'><b>当日里程：</b>"+carList.data[tx].positionLast.distance+" km</br></div>"
						+"<div id='app8_"+carList.data[tx].id+"'><b>总里程：</b>"+carList.data[tx].positionLast.totalDistance+" km</br></div>"
						+"<div id='app9_"+carList.data[tx].id+"'><b>状态：</b>"+carList.data[tx].positionLast.state2+"</br></div>"
						+"<div id='app10_"+carList.data[tx].id+"'><b>位置：</b>"+carList.data[tx].positionLast.memo+"</br></div>"
						+"<div id='app13_"+carList.data[tx].id+"'><b>OBD数据：</b><a href='javascript:opobd("+carList.data[tx].id+");'><font color='#0000FF'>详细</font></a></br></div>"
						+"<a id='track_"+carList.data[tx].id+"' onclick='openTrackFrame(this,event)' href='javascript:;'><font color='#0000FF'>跟踪</font> | </a><a id='playback_"+carList.data[tx].id+"' onclick='openBackFrame(this,event);' href='javascript:;'><font color='#0000FF'>回放</font> | </a>  <a id='more_"+carList.data[tx].id+"' href='javascript:;' onclick=\"showSecondMenu(this,event);\"><font color='#0000FF'>更多▼</font></a></p></div></div>";
					}
				    
				    var myIcon = new BMap.Icon(pngicon+image, new BMap.Size(32,32));
	    			var marker = new BMap.Marker(
	    					myLatlng
	    					,{icon:myIcon}
	    			);  // 创建标注
	    			baidMap.addOverlay(marker);
	    			var opts = {
					  position : myLatlng,    // 指定文本标注所在的地理位置
					  offset   : new BMap.Size(10, -10)    //设置文本偏移量
					 
					}
					var label = new BMap.Label(carList.data[tx].vhcCode,opts);  // 创建文本标注对象
					label.setStyle({
						 color : "#000000",
						 backgroundColor : "#f5fcb8",
						 borderColor : "#000000",
						 fontSize : "12px",
						 height : "16px",
						 lineHeight : "16px",
						 fontWeight:"bold",
						 fontFamily:""
					});
					if( namekg == false ){
						baidMap.addOverlay(label);
					}
					//baidMap.addOverlay(label); 
	    			//创建信息窗口
	    			var infoWindow = new BMap.InfoWindow(html);
	    			marker.addEventListener("click", function(){
	    				this.openInfoWindow(infoWindow);
	    				document.getElementById('weizhi').innerHTML = carList.data[tx].vhcCode+"： " + carList.data[tx].positionLast.memo;
						document.getElementById('weizhi').title = carList.data[tx].vhcCode+"： " + carList.data[tx].positionLast.memo;
						msgid= carList.data[tx].id;
						msgname= carList.data[tx].vhcCode;
	    			});
	    			var markerManage = new Object();
	    			markerManage.id = carList.data[tx].id;
	    			markerManage.remark= carList.data[tx].remark;
	    			markerManage.vhcCode = carList.data[tx].vhcCode;
	    			markerManage.label = label;
	    			markerManage.marker = marker;
	    			markerManage.icon = carList.data[tx].icon;
	    			markerManage.infowindow = infoWindow;
	    			markerManage.latlng = myLatlng;
	    			markerManage.simCode=carList.data[tx].simCode
	    			markers.push(markerManage);
				//}
			}
		})(i);
    }
	if(strNum+10<=carList.data.length){
			strNum=j+10;
			setTimeout("addMarkers("+(strNum-10)+","+strNum+")",100);
	}else{
			strNum=j;
			if(strNum<carList.data.length){
				var tNum = strNum;
				strNum=carList.data.length;
				setTimeout("addMarkers("+tNum+","+(carList.data.length)+")",100);
			}
	}
}
var drawingManager;
function baiduMap(ids,bool){
	//setT=setTimeout("MapData()",100);
	if(ids == ""){
		 setTimeout("baiduMap(ids)",5000);
	}else if(ids == "-1"){
		 baidMap = new BMap.Map("map_canvas");      // 创建地图实例    
		 var point = new BMap.Point(116.404, 39.915);  // 创建点坐标
		 baidMap.centerAndZoom(point,15);
	}else if(ids == "thresholds"){
		 baidMap = new BMap.Map("map_canvas");      // 创建地图实例    
		 var point = new BMap.Point(111, 34);  // 创建点坐标
		 baidMap.centerAndZoom(point, 5);
		 baidMap.addControl(new BMap.NavigationControl());  //缩放轴
		 baidMap.addControl(new BMap.OverviewMapControl());    //缩略图
		 baidMap.addControl(new BMap.MapTypeControl({mapTypes: [BMAP_NORMAL_MAP,BMAP_HYBRID_MAP ]})); //地图类型

		 baidMap.enableScrollWheelZoom(); //启用滚轮放大缩小
		 baidMap.addControl(new BMap.ScaleControl());   // 添加默认比例尺控件
		 
		 
		var frequency = 0;
		//alert(frequency+10+"   "+carList.data.length)
		if(carList !="null" && carList!="" && carList!= null){
			if(frequency+10<=carList.data.length){
					strNum=0;
					setTimeout("addMarkers("+frequency+","+(frequency+10)+")",500);
			}else{
					setTimeout("addMarkers("+frequency+","+(carList.data.length)+")",500);
				//addMarkers(i,carList.data.length);
			}
		}
	}else{
		
  			var lat=0,lng=0;
  			for(i=0;i<carList.data.length;i++){
  	  			if(carList.data[i].positionLast.blat != 0 &&carList.data[i].positionLast.blng != 0){
  	  				lat = carList.data[i].positionLast.blat;
  	  				lng = carList.data[i].positionLast.blng;
  	  				break;
  	  			}
  	  		}
  			baidMap = new BMap.Map("map_canvas");      // 创建地图实例    
  			var point = new BMap.Point(lng,lat);
  			if(lat==0 && lng==0){
  				baidMap.centerAndZoom(new BMap.Point(116.404, 39.915), 15);
  			}else{
  				baidMap.centerAndZoom(point, 15);
  			}
		    idsData=ids;
			closeMask();
		  // 创建点坐标
		// 初始化地图，设置中心点坐标和地图级别
		baidMap.addControl(new BMap.NavigationControl());  //缩放轴
		baidMap.addControl(new BMap.OverviewMapControl());    //缩略图
		baidMap.addControl(new BMap.MapTypeControl({mapTypes: [BMAP_NORMAL_MAP,BMAP_HYBRID_MAP ]})); //地图类型
		baidMap.enableScrollWheelZoom(); //启用滚轮放大缩小
		baidMap.addControl(new BMap.ScaleControl());   // 添加默认比例尺控件
		
		var styleOptions = {
		        strokeColor:"#5bcb63",    //边线颜色。
		        fillColor:"#5bcb63",      //填充颜色。当参数为空时，圆形将没有填充效果。
		        strokeWeight: 3,       //边线的宽度，以像素为单位。
		        strokeOpacity: 0.8,	   //边线透明度，取值范围0 - 1。
		        fillOpacity: 0.6,      //填充的透明度，取值范围0 - 1。
		        strokeStyle: 'solid' //边线的样式，solid或dashed。
	    }
		//实例化鼠标绘制工具
	    drawingManager = new BMapLib.DrawingManager(baidMap,{
	        isOpen: false, //是否开启绘制模式
	        enableDrawingTool: false, //是否显示工具栏
	        drawingType:BMAP_DRAWING_CIRCLE,
	        drawingToolOptions: {
	            anchor: BMAP_ANCHOR_TOP_RIGHT, //位置
	            offset: new BMap.Size(5,5), //偏离值
	        },
	        circleOptions: styleOptions, //圆的样式
	    });
		drawingManager.setDrawingMode(BMAP_DRAWING_CIRCLE);
		//添加鼠标绘制工具监听事件，用于获取绘制结果
		drawingManager.addEventListener('overlaycomplete',overlaycomplete);
		
		var frequency = 0;
		//alert(frequency+10+"   "+carList.data.length)
		
		if(frequency+10<=carList.data.length){
				strNum=0;
				setTimeout("addMarkers("+frequency+","+(frequency+10)+")",500);
		}else{
				setTimeout("addMarkers("+frequency+","+(carList.data.length)+")",500);
		}
	}
	var yanchiAl;
	baidMap.addEventListener("dragend", function showInfo(){
		clearTimeout(yanchiAl);
    	yanchiAl=setTimeout("al()",500);
	});
	if(baidubool == false){
		addMenu();
	}
	$("#checkbox1").click();
}
function updateBaiduMap(){
	for(var i=0;i<newdata.data.length;i++){
		for(var k=0;k<markers.length;k++){
			if(newdata.data[i].vehicleId == markers[k].id){
				/*
				if(msgid== newdata.data[i].vehicleId){
					document.getElementById('weizhi').innerHTML = msgname+"： " + newdata.data[i].memo;
					document.getElementById('weizhi').title = msgname+"： " + newdata.data[i].memo;
				}
				*/
				
				var x_pi = 3.14159265358979324 * 3000.0 / 180.0;
			
				var x = newdata.data[i].lng, y = newdata.data[i].lat;
				var z =Math.sqrt(x * x + y * y) + 0.00002 *Math.sin(y * x_pi);
				var theta =Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
				var lng = z *  Math.cos(theta) + 0.0065;
				var lat = z *  Math.sin(theta) + 0.006;
				var myLatlng = new BMap.Point(lng,lat);
				
				var s=10;
				var condition=newdata.data[i].state2;
			  	var sp = parseInt(newdata.data[i].speed);
			  	if (condition != null){
					if (condition.indexOf("不在线")>=0 || condition.indexOf("掉线")>=0)
							s = 2;
					else {
						if (condition.indexOf("速报警")>=0)
							s = 4;
						else if (condition.indexOf("报警")>=0)
							s = 3;
						else if (sp > 0.5)
							s = 0;
						else
							s = 1;
					}
					if (s != 4 && s != 3 && condition.indexOf("停车")>=0
							&& !condition.indexOf("不在线")>= 0){
									if(condition.indexOf("停车超时")>=0){
										s = 5;	
									}else{
										s = 6;
									}
							}
				}else{
					if (sp > 0.5)
						s = 0;
					else
						s = 1;
				}
			  	
			  	if( newdata.data[i].av == 0 ){
					s=7;
				}
			var newtime = new Date().getTime();
			var ttime =newdata.data[i].recvtime.replace("-","/");
			ttime=ttime.replace("-","/");
			ttime=ttime.replace("T"," ");
			var oldtime = new Date(ttime).getTime();
			//alert(newtime-oldtime);
			if(newtime-oldtime > 600000){
				s=2;
			}
		  	
		  	
		  
		  	var state =s;  
		  	
			
		  	var pngicon = "gpsonline/image/pic/"+markers[k].icon+"/red_0.gif";
			if(state == 0) pngicon = "gpsonline/image/pic/"+markers[k].icon+"/green_";
			else if(state == 1) pngicon = "gpsonline/image/pic/"+markers[k].icon+"/red_";
			else if(state == 2) pngicon = "gpsonline/image/pic/"+markers[k].icon+"/gray_";
			else if(state == 3) pngicon = "gpsonline/image/pic/"+markers[k].icon+"/yellow_";
			else if(state == 4) pngicon = "gpsonline/image/pic/"+markers[k].icon+"/pink_";
			else if(state == 5) pngicon = "gpsonline/image/pic/"+markers[k].icon+"/stopalarm";
			else if(state == 7) pngicon = "gpsonline/image/pic/"+markers[k].icon+"/blue_";
			else pngicon = "gpsonline/image/pic/"+markers[k].icon+"/red_";
					 var direction="";
					 var t = parseInt(newdata.data[i].direct);
					   if(t>27 && t<=72){
					  		if(state == 5){
					  			var image=".gif";
					  		}else{
					  			var image="45.gif";
					  		}
							direction="东北";
						}else if(t>72 && t<=117){
							if(state == 5){
					  			var image=".gif";
					  		}else{
					  			var image="90.gif";
					  		}
							
							direction="东";
						}
						else if(t>117 && t<=162){
							if(state == 5){
					  			var image=".gif";
					  		}else{
					  			var image="135.gif";
					  		}
							direction="东南";
						}
						else if(t>162 && t<=207){
							if(state == 5){
					  			var image=".gif";
					  		}else{
					  			var image="180.gif";
					  		}
							direction="南";
						}
						else if(t>207 && t<=252){
							if(state == 5){
					  			var image=".gif";
					  		}else{
					  			var image="225.gif";
					  		}
							direction="西南";
						}
						else if(t>252 && t<=297){
							if(state == 5){
					  			var image=".gif";
					  		}else{
					  			var image="270.gif";
					  		}
							direction="西";
						}
						else if(t>297 && t<=342){
							if(state == 5){
					  			var image=".gif";
					  		}else{
					  			var image="315.gif";
					  		}
							direction="西北";
						}
						else {
							if(state == 5){
					  			var image=".gif";
					  		}else{
					  			var image="0.gif";
					  		}
							direction="北";
						}
					
						var carname = encodeURI(encodeURI(markers[k].vhcCode));


					var temp,temp1,temp2,temp3,temp4;
					if(newdata.data[i].temperature != null && newdata.data[i].temperature <=100){
						temp=newdata.data[i].temperature +" ℃";
					}else{
						temp="无效";
					}
					if(newdata.data[i].temp1 != null && newdata.data[i].temp1 <=100){
						temp1=newdata.data[i].temp1 +" ℃";
					}else{
						temp1="无效";
					}
					if(newdata.data[i].temp2 != null && newdata.data[i].temp2 <=100){
						temp2=newdata.data[i].temp2 +" ℃";
					}else{
						temp2="无效";
					}
					if(newdata.data[i].temp3 != null && newdata.data[i].temp3 <=100){
						temp3=newdata.data[i].temp3 +" ℃";
					}else{
						temp3="无效";
					}
					if(newdata.data[i].temp4 != null && newdata.data[i].temp4 <=100){
						temp4=newdata.data[i].temp4 +" ℃";
					}else{
						temp4="无效";
					}
					var html="";
					if(alarmType=="Bus_client"){
						html = "<div id='app_"+newdata.data[i].vehicleId+"' style='font-weight:normal;'>"
					    +"<div id='app1_"+newdata.data[i].vehicleId+"'><b>设备名称：</b>"+markers[k].vhcCode+"</br></div>"
					    +"<div id='app14_"+newdata.data[i].vehicleId+"'><b>备注：</b>"+markers[k].remark+"</br></div>"
					    +"<div id='app11_"+newdata.data[i].vehicleId+"'><b>SIM卡号：</b>"+markers[k].simCode+"</br></div>"
						+"<div id='app2_"+newdata.data[i].vehicleId+"'><b>服务器时间：</b>"+newdata.data[i].recvtime+"</br></div>"
						+"<div id='app12_"+newdata.data[i].vehicleId+"'><b>GPS时间：</b>"+newdata.data[i].gpstime+"</br></div>"
						+"<div id='app3_"+newdata.data[i].vehicleId+"'><b>速度：</b>"+newdata.data[i].speed.toFixed(1)+"km/h </br></div>"
						+"<div id='app4_"+newdata.data[i].vehicleId+"'><b>方向：</b>"+direction+"</br></div>"
						+"<div id='app5_"+newdata.data[i].vehicleId+"'><b>温度：</b>"+temp+" | <b>温度1：</b>"+temp1+" | <b>温度2：</b>"+temp2+" | <b>温度3：</b>"+temp3+" | <b>温度4：</b>"+temp4+"</br></div>"
						+"<div id='app6_"+newdata.data[i].vehicleId+"'><b>油量：</b>"+newdata.data[i].oilMN1+" L</br></div>"
						+"<div id='app7_"+newdata.data[i].vehicleId+"'><b>当前里程：</b>"+newdata.data[i].distance+" km</br></div>"
						+"<div id='app8_"+newdata.data[i].vehicleId+"'><b>总里程：</b>"+newdata.data[i].totalDistance+" km</br></div>"
						+"<div id='app9_"+newdata.data[i].vehicleId+"'><b>状态：</b>"+newdata.data[i].state2+"</br></div>"
						+"<div id='app10_"+newdata.data[i].vehicleId+"'><b>位置：</b>"+newdata.data[i].memo+"</br></div>"
						+"<div id='app13_"+newdata.data[i].vehicleId+"'><b>OBD数据：</b><a href='javascript:opobd("+newdata.data[i].vehicleId+");'><font color='#0000FF'>详细</font></a></br></div>"
						+"<a id='track_"+newdata.data[i].vehicleId+"' onclick='openTrackFrame(this,event)' href='javascript:;'><font color='#0000FF'>跟踪</font> | </a><a id='' onclick='voiceStar(\""+newdata.data[i].voiceCode+"\",\""+newdata.data[i].dataCode+"\")' href='javascript:;'><font color='#0000FF'>视频</font> | </a><a id='playback_"+newdata.data[i].vehicleId+"' onclick='openBackFrame(this,event);' href='javascript:;'><font color='#0000FF'>回放</font> | </a>  <a id='more_"+newdata.data[i].vehicleId+"' href='javascript:;' onclick=\"showSecondMenu(this,event);\"><font color='#0000FF'>更多▼</font></a></p></div></div>";
					}else{
						html = "<div id='app_"+newdata.data[i].vehicleId+"' style='font-weight:normal;'>"
					    +"<div id='app1_"+newdata.data[i].vehicleId+"'><b>设备名称：</b>"+markers[k].vhcCode+"</br></div>"
					    +"<div id='app14_"+newdata.data[i].vehicleId+"'><b>备注：</b>"+markers[k].remark+"</br></div>"
					    +"<div id='app11_"+newdata.data[i].vehicleId+"'><b>SIM卡号：</b>"+markers[k].simCode+"</br></div>"
						+"<div id='app2_"+newdata.data[i].vehicleId+"'><b>服务器时间：</b>"+newdata.data[i].recvtime+"</br></div>"
						+"<div id='app12_"+newdata.data[i].vehicleId+"'><b>GPS时间：</b>"+newdata.data[i].gpstime+"</br></div>"
						+"<div id='app3_"+newdata.data[i].vehicleId+"'><b>速度：</b>"+newdata.data[i].speed.toFixed(1)+"km/h </br></div>"
						+"<div id='app4_"+newdata.data[i].vehicleId+"'><b>方向：</b>"+direction+"</br></div>"
						+"<div id='app5_"+newdata.data[i].vehicleId+"'><b>温度：</b>"+temp+" | <b>温度1：</b>"+temp1+" | <b>温度2：</b>"+temp2+" | <b>温度3：</b>"+temp3+" | <b>温度4：</b>"+temp4+"</br></div>"
						+"<div id='app6_"+newdata.data[i].vehicleId+"'><b>油量：</b>"+newdata.data[i].oilMN1+" L</br></div>"
						+"<div id='app7_"+newdata.data[i].vehicleId+"'><b>当前里程：</b>"+newdata.data[i].distance+" km</br></div>"
						+"<div id='app8_"+newdata.data[i].vehicleId+"'><b>总里程：</b>"+newdata.data[i].totalDistance+" km</br></div>"
						+"<div id='app9_"+newdata.data[i].vehicleId+"'><b>状态：</b>"+newdata.data[i].state2+"</br></div>"
						+"<div id='app10_"+newdata.data[i].vehicleId+"'><b>位置：</b>"+newdata.data[i].memo+"</br></div>"
						+"<div id='app13_"+newdata.data[i].vehicleId+"'><b>OBD数据：</b><a href='javascript:opobd("+newdata.data[i].vehicleId+");'><font color='#0000FF'>详细</font></a></br></div>"
						+"<a id='track_"+newdata.data[i].vehicleId+"' onclick='openTrackFrame(this,event)' href='javascript:;'><font color='#0000FF'>跟踪</font> | </a><a id='playback_"+newdata.data[i].vehicleId+"' onclick='openBackFrame(this,event);' href='javascript:;'><font color='#0000FF'>回放</font> | </a>  <a id='more_"+newdata.data[i].vehicleId+"' href='javascript:;' onclick=\"showSecondMenu(this,event);\"><font color='#0000FF'>更多▼</font></a></p></div></div>";
					}
						markers[k].latlng=myLatlng;
						markers[k].marker.setIcon(new BMap.Icon(pngicon+image, new BMap.Size(32,32)));
						markers[k].infowindow.setContent(html);
						markers[k].label.setContent(markers[k].vhcCode);
						if( newdata.data[i].lat != 0 && newdata.data[i].lng !=0){
							markers[k].marker.setPosition(myLatlng);	
							markers[k].infowindow.setPosition(myLatlng);
							markers[k].label.setPosition(myLatlng);
						}
						if(namekg == true){
							baidMap.removeOverlay(markers[k].label);
						}	
			}
		}
	}
}
function centerBaiduMap(data,db){
	/*for(var j=0;j<markers.length;j++){
		markers[j].infowindow.close();
	}*/
	//alert(111);
	msgid=data.data[0].id;
	msgname= data.data[0].vhcCode;
		for(var k=0;k<markers.length;k++){
			if(data.data[0].id == markers[k].id){
				//var myLatlng = new BMap.Point(data.data[0].positionLast.blng,data.data[0].positionLast.blat);
				
				var x_pi = 3.14159265358979324 * 3000.0 / 180.0;
				//alert(x_pi);
				
				var x =data.data[0].positionLast.lng , y = data.data[0].positionLast.lat;
				var z =Math.sqrt(x * x + y * y) + 0.00002 *Math.sin(y * x_pi);
				var theta =Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
				var lng = z *  Math.cos(theta) + 0.0065;
				var lat = z *  Math.sin(theta) + 0.006;
				var myLatlng = new BMap.Point(lng,lat);
				
				var s=10;
				var condition=data.data[0].positionLast.state2;
			  	var sp = parseInt(data.data[0].positionLast.speed);
			  	if (condition != null) {
				if (condition.indexOf("不在线")>=0 || condition.indexOf("掉线")>=0)
					s = 2;
				else {
					if (condition.indexOf("速报警")>=0)
						s = 4;
					else if (condition.indexOf("报警")>=0)
						s = 3;
					else if (sp > 0.5)
						s = 0;
					else
						s = 1;
				}
				if (s != 4 && s != 3 && condition.indexOf("停车")>=0
						&& !condition.indexOf("不在线")>= 0)
						{
						if(condition.indexOf("停车超时")>=0){
							s = 5;	
						}else{
							s = 6;
						}
					}
			}else{
				if (sp > 0.5)
					s = 0;
				else
					s = 1;
			}
			  	if( data.data[0].positionLast.av == 0 ){
					s=7;
				}
			var newtime = new Date().getTime();
						var ttime =data.data[0].positionLast.recvtime.replace("-","/");
						ttime=ttime.replace("-","/");
						ttime=ttime.replace("T"," ");
						var oldtime = new Date(ttime).getTime();
						if(newtime-oldtime > 600000){
							s=2;
						}
						
					  	var state =s;
					  	
		  	var pngicon = "gpsonline/image/pic/"+data.data[0].icon+"/red_0.gif";
			if(state == 0) pngicon = "gpsonline/image/pic/"+data.data[0].icon+"/green_";
			else if(state == 1) pngicon = "gpsonline/image/pic/"+data.data[0].icon+"/red_";
			else if(state == 2) pngicon = "gpsonline/image/pic/"+data.data[0].icon+"/gray_";
			else if(state == 3) pngicon = "gpsonline/image/pic/"+data.data[0].icon+"/yellow_";
			else if(state == 4) pngicon = "gpsonline/image/pic/"+data.data[0].icon+"/pink_";
			else if(state == 5) pngicon = "gpsonline/image/pic/"+data.data[0].icon+"/stopalarm";
			else if(state == 7) pngicon = "gpsonline/image/pic/"+data.data[0].icon+"/blue_";
			else pngicon = "gpsonline/image/pic/"+data.data[0].icon+"/red_";
					 var direction="";
					 var t = parseInt(data.data[0].positionLast.direct);
					  if(t>27 && t<=72){
					  		if(state == 5){
					  			var image=".gif";
					  		}else{
					  			var image="45.gif";
					  		}
							
							direction="东北";
						}else if(t>72 && t<=117){
							if(state == 5){
					  			var image=".gif";
					  		}else{
					  			var image="90.gif";
					  		}
							
							direction="东";
						}
						else if(t>117 && t<=162){
							if(state == 5){
					  			var image=".gif";
					  		}else{
					  			var image="135.gif";
					  		}
							direction="东南";
						}
						else if(t>162 && t<=207){
							if(state == 5){
					  			var image=".gif";
					  		}else{
					  			var image="180.gif";
					  		}
							direction="南";
						}
						else if(t>207 && t<=252){
							if(state == 5){
					  			var image=".gif";
					  		}else{
					  			var image="225.gif";
					  		}
							direction="西南";
						}
						else if(t>252 && t<=297){
							if(state == 5){
					  			var image=".gif";
					  		}else{
					  			var image="270.gif";
					  		}
							direction="西";
						}
						else if(t>297 && t<=342){
							if(state == 5){
					  			var image=".gif";
					  		}else{
					  			var image="315.gif";
					  		}
							direction="西北";
						}
						else {
							if(state == 5){
					  			var image=".gif";
					  		}else{
					  			var image="0.gif";
					  		}
							direction="北";
						}
			
	  			var carname = encodeURI(encodeURI(data.data[0].vhcCode)); 
				var temp,temp1,temp2,temp3,temp4;
					if(data.data[0].positionLast.temperature != null && data.data[0].positionLast.temperature <=100){
						temp=data.data[0].positionLast.temperature +" ℃";
					}else{
						temp="无效";
					}
					if(data.data[0].positionLast.temp1 != null && data.data[0].positionLast.temp1 <=100){
						temp1=data.data[0].positionLast.temp1 +" ℃";
					}else{
						temp1="无效";
					}
					if(data.data[0].positionLast.temp2 != null && data.data[0].positionLast.temp2 <=100){
						temp2=data.data[0].positionLast.temp2 +" ℃";
					}else{
						temp2="无效";
					}
					if(data.data[0].positionLast.temp3 != null && data.data[0].positionLast.temp3 <=100){
						temp3=data.data[0].positionLast.temp3 +" ℃";
					}else{
						temp3="无效";
					}
					if(data.data[0].positionLast.temp4 != null && data.data[0].positionLast.temp4 <=100){
						temp4=data.data[0].positionLast.temp4 +" ℃";
					}else{
						temp4="无效";
					}
					
					var html="";
					if(alarmType=="Bus_client"){
						html =	"<div id='app_"+data.data[0].id+"' style='font-weight:normal;'>"
					    +"<div id='app1_"+data.data[0].id+"'><b>设备名称：</b>"+data.data[0].vhcCode+"</br></div>"
					    +"<div id='app14_"+data.data[0].id+"'><b>备注：</b>"+data.data[0].remark+"</br></div>"
					    +"<div id='app11_"+data.data[0].id+"'><b>SIM卡号：</b>"+data.data[0].simCode+"</br></div>"
						+"<div id='app2_"+data.data[0].id+"'><b>服务器时间：</b>"+data.data[0].positionLast.recvtime+"</br></div>"
						+"<div id='app12_"+data.data[0].id+"'><b>GPS时间：</b>"+data.data[0].positionLast.gpstime+"</br></div>"
						+"<div id='app3_"+data.data[0].id+"'><b>速度：</b>"+data.data[0].positionLast.speed.toFixed(1)+"km/h </br></div>"
						+"<div id='app4_"+data.data[0].id+"'><b>方向：</b>"+direction+"</br></div>"
						+"<div id='app5_"+data.data[0].id+"'><b>温度：</b>"+temp+" | <b>温度1：</b>"+temp1+" | <b>温度2：</b>"+temp2+" | <b>温度3：</b>"+temp3+" | <b>温度4：</b>"+temp4+" </br></div>"
						+"<div id='app6_"+data.data[0].id+"'><b>油量：</b>"+data.data[0].positionLast.oilMN1+" L</br></div>"
						+"<div id='app7_"+data.data[0].id+"'><b>当日里程：</b>"+data.data[0].positionLast.distance+" km</br></div>"
						+"<div id='app8_"+data.data[0].id+"'><b>总里程：</b>"+data.data[0].positionLast.totalDistance+" km</br></div>"
						+"<div id='app9_"+data.data[0].id+"'><b>状态：</b>"+data.data[0].positionLast.state2+"</br></div>"
						+"<div id='app10_"+data.data[0].id+"'><b>位置：</b>"+data.data[0].positionLast.memo+"</br></div>"
						+"<div id='app13_"+data.data[0].id+"'><b>OBD数据：</b><a href='javascript:opobd("+data.data[0].id+");'><font color='#0000FF'>详细</font></a></br></div>"
						+"<a id='track_"+data.data[0].id+"' onclick='openTrackFrame(this,event)' href='javascript:;'><font color='#0000FF'>跟踪</font> | </a><a id='' onclick='voiceStar(\""+data.data[0].voiceCode+"\",\""+data.data[0].dataCode+"\")' href='javascript:;'><font color='#0000FF'>视频</font> | </a><a id='playback_"+data.data[0].id+"' onclick='openBackFrame(this,event);' href='javascript:;'><font color='#0000FF'>回放</font> | </a>  <a id='more_"+data.data[0].id+"' href='javascript:;' onclick=\"showSecondMenu(this,event);\"><font color='#0000FF'>更多▼</font></a></p></div></div>";
						   
						 
						   
					}else{
						html =	"<div id='app_"+data.data[0].id+"' style='font-weight:normal;'>"
					    +"<div id='app1_"+data.data[0].id+"'><b>设备名称：</b>"+data.data[0].vhcCode+"</br></div>"
					    +"<div id='app14_"+data.data[0].id+"'><b>备注：</b>"+data.data[0].remark+"</br></div>"
					    +"<div id='app11_"+data.data[0].id+"'><b>SIM卡号：</b>"+data.data[0].simCode+"</br></div>"
						+"<div id='app2_"+data.data[0].id+"'><b>服务器时间：</b>"+data.data[0].positionLast.recvtime+"</br></div>"
						+"<div id='app12_"+data.data[0].id+"'><b>GPS时间：</b>"+data.data[0].positionLast.gpstime+"</br></div>"
						+"<div id='app3_"+data.data[0].id+"'><b>速度：</b>"+data.data[0].positionLast.speed.toFixed(1)+"km/h </br></div>"
						+"<div id='app4_"+data.data[0].id+"'><b>方向：</b>"+direction+"</br></div>"
						+"<div id='app5_"+data.data[0].id+"'><b>温度：</b>"+temp+" | <b>温度1：</b>"+temp1+" | <b>温度2：</b>"+temp2+" | <b>温度3：</b>"+temp3+" | <b>温度4：</b>"+temp4+" </br></div>"
						+"<div id='app6_"+data.data[0].id+"'><b>油量：</b>"+data.data[0].positionLast.oilMN1+" L</br></div>"
						+"<div id='app7_"+data.data[0].id+"'><b>当日里程：</b>"+data.data[0].positionLast.distance+" km</br></div>"
						+"<div id='app8_"+data.data[0].id+"'><b>总里程：</b>"+data.data[0].positionLast.totalDistance+" km</br></div>"
						+"<div id='app9_"+data.data[0].id+"'><b>状态：</b>"+data.data[0].positionLast.state2+"</br></div>"
						+"<div id='app10_"+data.data[0].id+"'><b>位置：</b>"+data.data[0].positionLast.memo+"</br></div>"
						+"<div id='app13_"+data.data[0].id+"'><b>OBD数据：</b><a href='javascript:opobd("+data.data[0].id+");'><font color='#0000FF'>详细</font></a></br></div>"
						+"<a id='track_"+data.data[0].id+"' onclick='openTrackFrame(this,event)' href='javascript:;'><font color='#0000FF'>跟踪</font> | </a><a id='playback_"+data.data[0].id+"' onclick='openBackFrame(this,event);' href='javascript:;'><font color='#0000FF'>回放</font> | </a>  <a id='more_"+data.data[0].id+"' href='javascript:;' onclick=\"showSecondMenu(this,event);\"><font color='#0000FF'>更多▼</font></a></p></div></div>";
						
					}
	  			
				markers[k].marker.setIcon(new BMap.Icon(pngicon+image, new BMap.Size(32,32)));
				markers[k].infowindow.setContent(html);
			
				markers[k].label.setContent(markers[k].vhcCode);
				if(namekg == true){
					baidMap.removeOverlay(markers[k].label);
				}
				markers[k].marker.openInfoWindow(markers[k].infowindow);
				
				
				document.getElementById('weizhi').innerHTML = data.data[0].vhcCode+"： " + data.data[0].positionLast.memo;
				document.getElementById('weizhi').title = data.data[0].vhcCode+"： " + data.data[0].positionLast.memo;
				baidMap.setZoom(13);
			//	if(data.data[0].positionLast.blng != 0 && data.data[0].positionLast.blat != 0){
					 markers[k].latlng=myLatlng;
						markers[k].marker.setPosition(myLatlng);		
						markers[k].infowindow.setPosition(myLatlng);
						markers[k].label.setPosition(myLatlng);
			//	}
						if(db==1){
							baidMap.setCenter(myLatlng);
						}
				
			}
		}
	
}
function googleMap(){
		var data =carList;
		var lat = 0;
		var lng = 0;
		if(carList != "null" && carList!="" && carList!= null){
			if(data.flag==true){
	      		for(i=0;i<data.data.length;i++){
	      			if(data.data[i].positionLast.lat != 0 &&data.data[i].positionLast.lng != 0){
	      				lat = data.data[i].positionLast.lat;
	      				lng = data.data[i].positionLast.lng;
	      				break;
	      			}
	      		}
	      		if(lat==null && lng ==null){
		      		var mapOptions = {
				          center: new google.maps.LatLng(31.23, 121.47),
				          zoom: 4,
				          mapTypeId: google.maps.MapTypeId.ROADMAP,
				          mapTypeControlOptions: {
								mapTypeIds:[google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.SATELLITE, "MAPabc"]
						  }
					};
				        	 map = new google.maps.Map(document.getElementById("map_canvas"),
				                mapOptions);
				             addMAPabc(map);
				             var geocoder = new google.maps.Geocoder(); 
						    geocoder.geocode( { 'address': remote_ip_info.city}, function(results, status) { 
						      if (status == google.maps.GeocoderStatus.OK) { 
						      	 map.setCenter(results[0].geometry.location);
						      	 map.setZoom(8);
						      } else { 
						        //alert("Geocode was not successful for the following reason: " + status); 
						      } 
		    				}); 
	      		}else{
	      			/*
		      		if(alSwitch == false){
		      			countDown();    //每隔15秒执行函数al
		      			alSwitch = true;
		      		}
		      		*/
	      		var obj = getUserStatus();
	      		if(obj==null){
	      			mapOptions = {
			          center: new google.maps.LatLng(lat,lng),
			          zoom: 10,
			          mapTypeId: google.maps.MapTypeId.ROADMAP,
				          mapTypeControlOptions: {
									                    mapTypeIds: [google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.SATELLITE, "MAPabc"]
									                }
		       		};
	      		}else{
	      			var zoom;
	      			
	      			if(obj.bzoom == "" || obj.bzoom==null){
	          				zoom=6;
	          		}else{
	          				zoom=obj.bzoom-1;
	          		}
	      			
	      			mapOptions = {
			          center: new google.maps.LatLng(obj.lat,obj.lng),
			          zoom: zoom,
			          mapTypeId: google.maps.MapTypeId.ROADMAP,
				          mapTypeControlOptions: {
									                    mapTypeIds: [google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.SATELLITE, "MAPabc"]
									                }
		       		};
	      		}
	      		
		        map = new google.maps.Map(document.getElementById("map_canvas"),
		            mapOptions);
		            addMAPabc(map);
		         
		        for(i=0;i<data.data.length;i++){
		    		(function(x){
		    		var myLatlng = new google.maps.LatLng(data.data[x].positionLast.lat,data.data[x].positionLast.lng);
						
					var s=10;
					var condition=data.data[x].positionLast.state2;
				  	var sp = parseInt(data.data[x].positionLast.speed);
				  	if (condition != null) {
					if (condition.indexOf("不在线")>=0 || condition.indexOf("掉线")>=0)
						s = 2;
					else {
						if (condition.indexOf("速报警")>=0)
							s = 4;
						else if (condition.indexOf("报警")>=0)
							s = 3;
						else if (sp > 0.5)
							s = 0;
						else
							s = 1;
					}
					if (s != 4 && s != 3 && condition.indexOf("停车")>=0
							&& !condition.indexOf("不在线")>= 0)
						{
							if(condition.indexOf("停车超时")>=0){
								s = 5;	
							}else{
								s = 6;
							}
						}
				}else{
					if (sp > 0.5)
						s = 0;
					else
						s = 1;
				}
				  	if( data.data[i].positionLast.av == 0 ){
						s=7;
					}
				var newtime = new Date().getTime();
							var ttime =data.data[i].positionLast.recvtime.replace("-","/");
							ttime=ttime.replace("-","/");
							ttime=ttime.replace("T"," ");
							var oldtime = new Date(ttime).getTime();
							if(newtime-oldtime > 600000){
								s=2;
							}
							
						  	
							
			  	var state =s;
			  	var pngicon = "gpsonline/image/pic/"+data.data[x].icon+"/red_0.gif";
				if(state == 0) pngicon = "gpsonline/image/pic/"+data.data[x].icon+"/green_";
				else if(state == 1) pngicon = "gpsonline/image/pic/"+data.data[x].icon+"/red_";
				else if(state == 2) pngicon = "gpsonline/image/pic/"+data.data[x].icon+"/gray_";
				else if(state == 3) pngicon = "gpsonline/image/pic/"+data.data[x].icon+"/yellow_";
				else if(state == 4) pngicon = "gpsonline/image/pic/"+data.data[x].icon+"/pink_";
				else if(state == 5) pngicon = "gpsonline/image/pic/"+data.data[x].icon+"/stopalarm";
				else if(state == 7) pngicon = "gpsonline/image/pic/"+data.data[x].icon+"/blue_";
				else pngicon = "gpsonline/image/pic/"+data.data[x].icon+"/red_";
						 var direction="";
						 var t = parseInt(data.data[x].positionLast.direct);
						  if(t>27 && t<=72){
						  		if(state == 5){
						  			var image=".gif";
						  		}else{
						  			var image="45.gif";
						  		}
								direction="东北";
							}else if(t>72 && t<=117){
								if(state == 5){
						  			var image=".gif";
						  		}else{
						  			var image="90.gif";
						  		}
								
								direction="东";
							}
							else if(t>117 && t<=162){
								if(state == 5){
						  			var image=".gif";
						  		}else{
						  			var image="135.gif";
						  		}
								direction="东南";
							}
							else if(t>162 && t<=207){
								if(state == 5){
						  			var image=".gif";
						  		}else{
						  			var image="180.gif";
						  		}
								direction="南";
							}
							else if(t>207 && t<=252){
								if(state == 5){
						  			var image=".gif";
						  		}else{
						  			var image="225.gif";
						  		}
								direction="西南";
							}
							else if(t>252 && t<=297){
								if(state == 5){
						  			var image=".gif";
						  		}else{
						  			var image="270.gif";
						  		}
								direction="西";
							}
							else if(t>297 && t<=342){
								if(state == 5){
						  			var image=".gif";
						  		}else{
						  			var image="315.gif";
						  		}
								direction="西北";
							}
							else {
								if(state == 5){
						  			var image=".gif";
						  		}else{
						  			var image="0.gif";
						  		}
								direction="北";
							}
					    var marker = new google.maps.Marker({
						      position: myLatlng,
						      map: map,
						      icon: new google.maps.MarkerImage(pngicon+image, new google.maps.Size(32, 32),new google.maps.Point(0,0),new google.maps.Point(10, 10)),
						      title:data.data[x].vhcCode
						});
					
	    				var carname = encodeURI(encodeURI(data.data[x].vhcCode)); 
						markersArray.push(marker);
						
						
					var temp,temp1,temp2,temp3,temp4;
					if(data.data[x].positionLast.temperature != null && data.data[x].positionLast.temperature <=100){
						temp=data.data[x].positionLast.temperature +" ℃";
					}else{
						temp="无效";
					}
					if(data.data[x].positionLast.temp1 != null && data.data[x].positionLast.temp1 <=100){
						temp1=data.data[x].positionLast.temp1 +" ℃";
					}else{
						temp1="无效";
					}
					if(data.data[x].positionLast.temp2 != null && data.data[x].positionLast.temp2 <=100){
						temp2=data.data[x].positionLast.temp2 +" ℃";
					}else{
						temp2="无效";
					}
					if(data.data[x].positionLast.temp3 != null && data.data[x].positionLast.temp3 <=100){
						temp3=data.data[x].positionLast.temp3 +" ℃";
					}else{
						temp3="无效";
					}
					if(data.data[x].positionLast.temp4 != null && data.data[x].positionLast.temp4 <=100){
						temp4=data.data[x].positionLast.temp4 +" ℃";
					}else{
						temp4="无效";
					}
						
						 var contentString = document.createElement("div");
						 contentString.className = "map_tanchu_wrap";
						 if(alarmType=="Bus_client"){
								contentString.innerHTML = "<b class='xtop'>" +
							    	"<b class='xb1'></b>" +
							        "<b class='xb2'></b>" +
							        "<b class='xb3'></b>" +
							        "<b class='xb4'></b>" +
							    "</b>" +
							    "<div class='xboxcontent'><p>" +
								"<b>设备名称：</b>"+data.data[x].vhcCode+"</br>"
								+"<b>SIM卡号：</b>"+data.data[x].simCode+"</br>"
								+"<b>接收时间：</b>"+data.data[x].positionLast.recvtime+"</br>"
								+"<b>速度：</b>"+data.data[x].positionLast.speed+"km/h </br>"
								+"<b>方向：</b>"+direction+"</br>"
								+"<b>温度：</b>"+temp+" | <b>温度1：</b>"+temp1+" | <b>温度2：</b>"+temp2+"<br><b>温度3：</b>"+temp3+" | <b>温度4：</b>"+temp4+"</br>"
								+"<b>油量：</b>"+data.data[x].positionLast.oilMN1+" L</br>"
								+"<b>当日里程：</b>"+data.data[x].positionLast.distance+" km</br>"
								+"<b>总里程：</b>"+data.data[x].positionLast.totalDistance+" km</br>"
								+"<b>状态：</b>"+data.data[x].positionLast.state2+"</br>"
								+"<b>位置：</b>"+data.data[x].positionLast.memo+"</br>"
								+"<b>OBD数据：</b><a href='javascript:opobd("+data.data[x].id+");'><font color='#0000FF'>详细</font></a></br>"
								+"<a id='track_"+data.data[x].id+"' onclick='openTrackFrame(this,event)' href='javascript:;'><font color='#0000FF'>跟踪</font> | </a><a id='' onclick='voiceStar(\""+data.data[x].voiceCode+"\",\""+data.data[x].dataCode+"\")' href='javascript:;'><font color='#0000FF'>视频</font> | </a><a id='playback_"+data.data[x].id+"' onclick='openBackFrame(this,event);' href='javascript:;'><font color='#0000FF'>回放</font> | </a>  <a id='more_"+data.data[x].id+"' href='javascript:;' onclick=\"showSecondMenu(this,event);\"><font color='#0000FF'>更多▼</font></a></p></div><b class='xbottom'><b class='xb4'></b><b class='xb3'></b><b class='xb2'></b><b class='xb1'></b></b><span class='arrow_bg'></span><span class='arrow'></span>";
							} else{
								contentString.innerHTML = "<b class='xtop'>" +
							    	"<b class='xb1'></b>" +
							        "<b class='xb2'></b>" +
							        "<b class='xb3'></b>" +
							        "<b class='xb4'></b>" +
							    "</b>" +
							    "<div class='xboxcontent'><p>" +
								"<b>设备名称：</b>"+data.data[x].vhcCode+"</br>"
								+"<b>SIM卡号：</b>"+data.data[x].simCode+"</br>"
								+"<b>接收时间：</b>"+data.data[x].positionLast.recvtime+"</br>"
								+"<b>速度：</b>"+data.data[x].positionLast.speed+"km/h </br>"
								+"<b>方向：</b>"+direction+"</br>"
								+"<b>温度：</b>"+temp+" | <b>温度1：</b>"+temp1+" | <b>温度2：</b>"+temp2+"<br><b>温度3：</b>"+temp3+" | <b>温度4：</b>"+temp4+"</br>"
								+"<b>油量：</b>"+data.data[x].positionLast.oilMN1+" L</br>"
								+"<b>当日里程：</b>"+data.data[x].positionLast.distance+" km</br>"
								+"<b>总里程：</b>"+data.data[x].positionLast.totalDistance+" km</br>"
								+"<b>状态：</b>"+data.data[x].positionLast.state2+"</br>"
								+"<b>位置：</b>"+data.data[x].positionLast.memo+"</br>"
								+"<b>OBD数据：</b><a href='javascript:opobd("+data.data[x].id+");'><font color='#0000FF'>详细</font></a></br>"
								+"<a id='track_"+data.data[x].id+"' onclick='openTrackFrame(this,event)' href='javascript:;'><font color='#0000FF'>跟踪</font> | </a><a id='playback_"+data.data[x].id+"' onclick='openBackFrame(this,event);' href='javascript:;'><font color='#0000FF'>回放</font> | </a>  <a id='more_"+data.data[x].id+"' href='javascript:;' onclick=\"showSecondMenu(this,event);\"><font color='#0000FF'>更多▼</font></a></p></div><b class='xbottom'><b class='xb4'></b><b class='xb3'></b><b class='xb2'></b><b class='xb1'></b></b><span class='arrow_bg'></span><span class='arrow'></span>";
							}
	   
						 var myOptions = {
								 content: contentString
								,disableAutoPan: false
								,maxWidth: 0
								,pixelOffset: new google.maps.Size(-163, -200)
								,zIndex: null
								,boxStyle: { 
								
								   background: "no-repeat"								  
								   ,width: "430px"
								 }
								,closeBoxMargin: "10px 35px 0px -20px"
								,closeBoxURL: "gpsonline/image/monitor/close.gif"
								,infoBoxClearance: new google.maps.Size(1, 1)
								,isHidden: false
								,pane: "floatPane"
								,enableEventPropagation: false
							};
							 
						 var infowindow = new InfoBox(myOptions);			 
		  
		 
		google.maps.event.addListener(marker, "click", function (e) {
		
		  
		 	markerObject.closeInfowindow();//关闭打开的标注弹出框
	    	if(menu!=null){
	        	menu.hide();
	        }
		    for(var i=0;i<vehicles.length;i++){
		          vehicles[i].infowindow.close();
		    }			    
			infowindow.open(map, this);
			document.getElementById('weizhi').innerHTML = data.data[x].vhcCode+"： " + data.data[x].positionLast.memo;
			document.getElementById('weizhi').title = data.data[x].vhcCode+"： " + data.data[x].positionLast.memo;
			
			
			
		});
						var vehicle = new Object();
					    vehicle.id = data.data[x].id;
					    vehicle.vhcCode = data.data[x].vhcCode;
						vehicle.label = new LableMarker(map,data.data[x].vhcCode,myLatlng);
						//vehicle.label.setMap(null);
						vehicle.marker = marker;
						vehicle.icon = data.data[x].icon;
						vehicle.infowindow = infowindow;
						vehicle.latlng = myLatlng;
						vehicle.simCode = data.data[x].simCode;
						if(data.data[x].positionLast.lat == 0 &&data.data[x].positionLast.lng == 0){
							//vehicle.marker.setMap(null);
							//vehicle.label.setMap(null);
						}
						vehicles.push(vehicle);
		    		})(i);
		         }	
		         }
			 }
		}else{
			var obj = getUserStatus();
      		if(obj==null){
      			var mapOptions = {
  			          center: new google.maps.LatLng(31.23, 121.47),
  			          zoom: 4,
  			          mapTypeId: google.maps.MapTypeId.ROADMAP,
  			          mapTypeControlOptions: {
  	                    mapTypeIds: [google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.SATELLITE, "MAPabc"]
  	                }
  			     };
  	        	 map = new google.maps.Map(document.getElementById("map_canvas"),
  	                mapOptions);
  	             addMAPabc(map);
  	             var geocoder = new google.maps.Geocoder(); 
  					    geocoder.geocode( { 'address': remote_ip_info.city}, function(results, status) { 
  					      if (status == google.maps.GeocoderStatus.OK) { 
  					      	 map.setCenter(results[0].geometry.location);
  					      	 map.setZoom(8);
  					      } else { 
  					      
  					      } 
  	    				}); 
      		}else{
      			var zoom;
      			if(obj.bzoom == "" || obj.bzoom==null){
          				zoom=6;
          		}else{
          				zoom=obj.bzoom-1;
          		}
      			var mapOptions = {
		          center: new google.maps.LatLng(obj.lat,obj.lng),
		          zoom: zoom,
		          mapTypeId: google.maps.MapTypeId.ROADMAP,
			          mapTypeControlOptions: {
								                    mapTypeIds: [google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.SATELLITE, "MAPabc"]
								                }
	       		};
      			map = new google.maps.Map(document.getElementById("map_canvas"),
    		            mapOptions);
    		            addMAPabc(map);
      		}	
			
  		}
	 google.maps.event.addListener(map, 'drag', function(){
        	clearTimeout(yanchiAl);
        	yanchiAl=setTimeout("al()",500);
     });
 }
var drawingManager;
var counts = 0;
var overlays = [];
var overlaycomplete = function(e){
	overlays.push(e.overlay);
    for( var i = 0; i < carList.data.length; i++){
    	var x_pi = 3.14159265358979324 * 3000.0 / 180.0;
		var x = carList.data[i].positionLast.lng, y = carList.data[i].positionLast.lat;
		var z = Math.sqrt(x * x + y * y) + 0.00002 *Math.sin(y * x_pi);
		var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
		var lng = z *  Math.cos(theta) + 0.0065;
		var lat = z *  Math.sin(theta) + 0.006;
		var bpoints = new BMap.Point(lng,lat);//每个车位置
		var point = e.overlay.getCenter();//圆心位置
		var radius = e.overlay.getRadius();//半径
		
		var dis = baidMap.getDistance(bpoints,point);
    	
    	if(dis < radius){
    		if($("#nearvehicles").css("display")!="block"){
				$("#nearvehicles").show();
	        }
			counts ++;
			var html="<div onclick='centerMap("+carList.data[i].id+",0);' class='chepainame'>"+carList.data[i].vhcCode+"</div>";
			$("#nearvhcs").append(html);
		}
    }
    $("#nearvhcscounts").html("范围内车辆("+counts+")");
    drawingManager.close();
};
function begHuaYuan(){
	drawingManager.open();
	$("#nearvhcs").empty();
	counts = 0;
	for ( var i = 0; i < overlays.length; i++){
		baidMap.removeOverlay(overlays[i]);
	}
}
function divhide(){
	drawingManager.close();
	$("#nearvhcscounts").html("范围内车辆");
	$("#nearvhcs").empty();
	counts = 0;
	for ( var i = 0; i < overlays.length; i++){
		baidMap.removeOverlay(overlays[i]);
	}
	$('#nearvehicles').hide();
}
//初始化
$(function(){

});