首页 > 代码库 > GPS、基站定位在百度地图上纠偏的解决方法

GPS、基站定位在百度地图上纠偏的解决方法

1.加入convertor.js文件

<script type="text/javascript" src="http://api.map.baidu.com/getscript?v=1.4"></script><script type="text/javascript" src="http://dev.baidu.com/wiki/static/map/API/examples/script/convertor.js"></script>

 

2.添加百度地图标注

function loadMarker(x,y,oap_name){	if(!x){return}	//纠正gps偏差		var iconv="../../../icons/access_point_b64.gif";	var iconu="../../../icons/access_point_r64.gif";	var iconSize = new BMap.Size(64, 64);//标注图片大小	var offsetSize = new BMap.Size(32, 32);//偏移位	//var point = new BMap.Point(x,y);	var icon = new BMap.Icon(iconv,iconSize, {		anchor:offsetSize	});	translateCallback = function (point) {		map.clearOverlays();		map.setCenter(point);		var marker = new BMap.Marker(point, {icon:icon});				marker.addEventListener("mouseover", function(){			this.setIcon(new BMap.Icon(iconu,iconSize,{anchor:offsetSize}));		});				marker.addEventListener("mouseout", function () {			this.setIcon(new BMap.Icon(iconv,iconSize,{				anchor:offsetSize			}));		});					map.centerAndZoom(point,16);				map.addOverlay(marker);				var gc = new BMap.Geocoder();		var infoWindow1=null;		gc.getLocation(point, function(rs){			var addComp = rs.addressComponents;			infoWindow1 = new BMap.InfoWindow("<div style=‘margin-top: 13px;font-size:15px;color:red;font-weight:bold;‘>"+oap_name+"</div><div style=‘margin-top: 5px;font-size: 13px;‘>地址:"+addComp.province + addComp.city +  addComp.district +  addComp.street + addComp.streetNumber+"<br/>经度:"+x+"<br/>纬度:"+y+"</div>");			marker1.openInfoWindow(infoWindow1);		}); 		marker.addEventListener("click", function(){this.openInfoWindow(infoWindow1);});	}		BMap.Convertor.translate(new BMap.Point(x, y), 0, translateCallback);}

3.最终显示结果如下:

大功告成。

GPS、基站定位在百度地图上纠偏的解决方法