• 把原始坐标转化为百度坐标(位置更精确)


    <!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 { 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=Q7hhQzxGQt1Ea0Gg1crZjrSWvtY9eqkR"></script>
    <title>GPS转百度</title>
    </head>
    <body>
    <div id="allmap"></div>
    </body>
    </html>
    <script type="text/javascript">
    if (navigator.geolocation)
    {
    navigator.geolocation.getCurrentPosition(showPosition);
    }

    function showPosition(position){

    var lo=position.coords.longitude;
    var la=position.coords.latitude;
    // 百度地图API功能
    //GPS坐标

    var ggPoint = new BMap.Point(lo,la);

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

    //添加gps marker和label
    /*var markergg = new BMap.Marker(ggPoint);
    bm.addOverlay(markergg); //添加GPS marker
    var labelgg = new BMap.Label("未转换的GPS坐标(错误)",{offset:new BMap.Size(20,-10)});
    markergg.setLabel(labelgg); //添加GPS label*/

    //坐标转换完之后的回调函数
    translateCallback = function (data){
    if(data.status === 0) {
    var marker = new BMap.Marker(data.points[0]);
    bm.addOverlay(marker);
    var label = new BMap.Label("转换后的百度坐标(正确)",{offset:new BMap.Size(20,-10)});
    marker.setLabel(label); //添加百度label
    bm.setCenter(data.points[0]);
    }
    }

    setTimeout(function(){
    var convertor = new BMap.Convertor();
    var pointArr = [];
    pointArr.push(ggPoint);
    convertor.translate(pointArr, 1, 5, translateCallback)
    }, 1000);

    }

    </script>

  • 相关阅读:
    [翻译]Linux 内核里的数据结构 —— 基数树
    spring各版本下载地址
    两台机子的repcached Memcache 的安装与实验
    非root用户Memcached repcached安装
    VMVare 桥接上网
    JDBC executeBatch 抛出异常停止
    Ehcache jgroups方式同步缓存出现问题总结
    jquery $提示缺少对象$提示缺少对象
    Struts2标签遍历List<Map<String,String>>
    linux与windows回车换行符的区别
  • 原文地址:https://www.cnblogs.com/yaomengli/p/6781865.html
Copyright © 2020-2023  润新知