GPS座標轉百度座標

$GNGGA,082725.000,3157.9020,N,11716.6617,E,1,5,1.79,22.9,M,0.3,M,,*45

$GNRMC,082725.000,A,3157.9020,N,11716.6617,E,1.731,319.89,191119,,,A*49

true    true    E    117.2776533    N    31.9650716    23    5    322    13    5

轉換後的座標是原始座標,百度高德是不認了,認了就違法了,轉換的算法不知道,也沒必要知道,機密哈。

以下座標gps座標,獲得的位置是不對的。通過座標查找位置:http://api.map.baidu.com/lbsapi/getpoint/index.html

 轉換後的與沒轉換的對比,誤差1km左右

 以下是網頁轉換源碼,粘貼複製保存後綴名.html然後雙擊打開就好了。



<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
        body, html, #allmap {
            width: 100%;
            height: 100%;
            overflow: hidden;
            margin: 0;
            font-family: "微軟雅黑";
        }
    </style>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=QXwuA2Zi8h3huVQvqVrW2MhU"></script>
    <script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>
    
    <title>GPS地圖</title>
</head>
<body>
	<div id="allmap"></div>
</body>
</html>



<script type="text/javascript">
//GPS原始座標
var xx = 117.2776533;
var yy = 31.9650716;
var gpsPoint = new BMap.Point(xx,yy);

//地圖初始化
var bm = new BMap.Map("allmap");
bm.centerAndZoom(gpsPoint, 15);
bm.addControl(new BMap.NavigationControl());

//添加谷歌marker和label
var markergps = new BMap.Marker(gpsPoint);
bm.addOverlay(markergps); //添加GPS標註
var labelgps = new BMap.Label("原始GPS座標",{offset:new BMap.Size(20,-10)});
markergps.setLabel(labelgps); //添加GPS標註

//座標轉換完之後的回調函數
translateCallback = function (point){
    var marker = new BMap.Marker(point);
    bm.addOverlay(marker);
    var label = new BMap.Label("百度轉換後的座標位置",{offset:new BMap.Size(20,-10)});
    marker.setLabel(label); //添加百度label
    bm.setCenter(point);
    alert("轉化爲百度座標爲:"+point.lng + "," + point.lat);
}

setTimeout(function(){
    BMap.Convertor.translate(gpsPoint,0,translateCallback);     //真實經緯度轉成百度座標
}, 2000);
</script>




 修改座標。

言歸正傳,獲得百度座標(網頁源碼裏添加gps座標)

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章