首页 > 代码库 > 坐标修正

坐标修正

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>常用坐标转换</title>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
<script type="text/javascript" src="http://dev.baidu.com/wiki/static/map/API/examples/script/convertor.js"></script></head>
<body>
<div style="width:520px;height:340px;border:1px solid gray" id="container"></div>
<div>谷歌(lng,lat)
<input style="width:150px" value="http://www.mamicode.com/116.32715863448607" type="text" id="ggX" /><input style="width:150px" value="http://www.mamicode.com/39.990912172420714" type="text" id="ggY" /><input value="http://www.mamicode.com/google->baidu" type="button" onclick="ggxy()" />
GPS(lng,lat)
<input style="width:150px" value="http://www.mamicode.com/116.397428" type="text" id="gpsX" /><input style="width:150px" value="http://www.mamicode.com/39.90923" type="text" id="gpsY" /><input value="http://www.mamicode.com/GPS->baidu" type="button" onclick="gpsxy()" />
百度(lng,lat)
<span id="baiduXY"> </span></div>
</body>
</html>
<script type="text/javascript">

var bm = new BMap.Map("container");
var point = new BMap.Point(116.404844,39.923125);
bm.centerAndZoom(point, 15);
bm.addControl(new BMap.NavigationControl());

ggxy = function (){
var x = document.getElementById("ggX").value;
var y = document.getElementById("ggY").value;
var ggPoint = new BMap.Point(x,y);
BMap.Convertor.translate(ggPoint,2,translateCallback);
}

gpsxy = function (){
var xx = document.getElementById("gpsX").value;
var yy = document.getElementById("gpsY").value;
var gpsPoint = new BMap.Point(xx,yy);
BMap.Convertor.translate(gpsPoint,0,translateCallback);
}
translateCallback = function (point){
bm.clearOverlays();
var marker = new BMap.Marker(point);
bm.addOverlay(marker);
bm.setCenter(point);
document.getElementById("baiduXY").innerHTML = point.lng + "," + point.lat;
}
</script>

坐标修正