码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-09-20 19:04:09      阅读:1648      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   io   os   java   ar   

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.最终显示结果如下:

bubuko.com,布布扣

大功告成。

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

标签:des   style   blog   http   color   io   os   java   ar   

原文地址:http://www.cnblogs.com/denisYuan/p/3983351.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!