• GPS坐标与百度坐标转换


    百度对外接口的坐标系,都是经过国家测绘局加密处理,符合国家测绘局对地理信息保密要求。

    国际经纬度坐标标准为WGS-84,国内必须至少使用国测局制定的GCJ- 02,对地理位置进行首次加密。百度坐标在此基础上,进行了BD-09二次加密措施,更加保护了个人隐私。百度对外接口的坐标系并不是GPS采集的真实经 纬度,需要通过坐标转换接口进行转换。

    百度地图坐标转换接口如下:  

      BMap.Convertor.translate(gpsPoint,0,translateCallback);     //真实经纬度转成百度坐标

    其中gpsPoint var gpsPoint = new BMap.Point(经度,纬度); ( GPS坐标)    0:代表GPS,也可以是2:google坐标    translateCallback:回掉函数

     

     

    下面是完整的测试GPS坐标转换百度坐标JS源码:

     

    复制代码
    复制代码
    复制代码
    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style type="text/css">
    body, html,#allmap { 100%;height: 100%;overflow: hidden;margin:0;}
    #l-map{height:100%;78%;float:left;border-right:2px solid #bcbcbc;}
    #r-result{height:100%;20%;float:left;}
    </style>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.5&ak=ofB5rD1KWbtxVkTAIqscalKf2uOf55En"></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.126575995835;
    var yy = 36.6702207308909;
    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>
    复制代码
    复制代码
    复制代码

     

    找到百度的API转换方法为:

     

        http://api.map.baidu.com/ag/coord/convert?from=0&to=4&x=longitude&y=latitude

     

        其中:
        from: 来源坐标系   (0表示原始GPS坐标,2表示Google坐标)
          to: 转换后的坐标   (4就是百度自己啦,好像这个必须是4才行)
            x: 经度
                y: 纬度
                返回的结果是一个json字符串:
               {"error":0,"x":"MTIxLjUwMDIyODIxNDk2","y":"MzEuMjM1ODUwMjYwMTE3"}

     

                其中:
                error:是结果是否出错标志位,"0"表示OK
                x: 百度坐标系的经度(Base64加密)
                y: 百度坐标系的纬度(Base64加密)

     

  • 相关阅读:
    (转)MapReduce源码分析总结
    Linux SSH远程文件/目录传输命令scp
    Hadoop学习总结:MapReduce的过程解析
    Python 3 的新特性zz
    Tutorial Learn Python in 10 minutes[zz]
    Hadoop学习总结:Hadoop的运行痕迹
    Python 绝对简明手册
    Linux命令总结
    [Error] 'strlen' was not declared in this scope
    养成C#编程好习惯
  • 原文地址:https://www.cnblogs.com/fanshaokun/p/7218455.html
Copyright © 2020-2023  润新知