百度地图API:Google/GPS坐标转为百度坐标工具

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Google/GPS坐标转为百度坐标工具-Mzwu.COM</title>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.2"></script>
<script type="text/javascript" src="http://dev.baidu.com/wiki/static/map/API/examples/script/convertor.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    var map = new BMap.Map("container", {mapType:BMAP_HYBRID_MAP});
    map.addControl(new BMap.NavigationControl());
    map.addControl(new BMap.MapTypeControl());

    //坐标转换回调函数
    translateCallback = function(point){
        $("#txtLng2").val(point.lng);
        $("#txtLat2").val(point.lat);    
        
        map.clearOverlays();
        var marker = new BMap.Marker(point);
        map.addOverlay(marker);
        map.centerAndZoom(point, 18);
    }
    //坐标转换
    $("#btnTranslate").click(function(){
        var lng = $("#txtLng1").val();
        var lat = $("#txtLat1").val();
        var type = $("#txtType").val();
        var point = new BMap.Point(lng, lat);
        BMap.Convertor.translate(point,type,translateCallback);
    });
});
</script>
</head>
<body>
经度:<input type="text" name="txtLng1" id="txtLng1" />
<br />
纬度:<input type="text" name="txtLat1" id="txtLat1" />
<br />
类型:
<select name="txtType" id="txtType">
  <option value="0">GPS坐标</option>
  <option value="2">Google坐标</option>
</select>
<br />
<br />
<input type="button" name="btnTranslate" id="btnTranslate" value="开始转换" />
<br />
<br />
经度:<input type="text" name="txtLng2" id="txtLng2" />
<br />
纬度:<input type="text" name="txtLat2" id="txtLat2" />
<br />
<br />
<div style="width:520px;height:340px;border:1px solid gray" id="container"></div>
</body>
</html>

参考资料

[1].百度坐标为何有偏移:http://openapi.baidu.com/map/faq.html#l8
[2].坐标转换:http://openapi.baidu.com/map/examples.html?v=1.2&0_5#0&5

评论: 0 | 引用: 0 | 查看次数: 6576
发表评论
登录后再发表评论!