百度地图API----搜索地址,获取该点的位置坐标并转换成WebMercator

function doFind(){
    LoadBaiduMapScript().then(BaiduMap).then(function () {
        //查询并获取坐标
        var myGeo  = new BMap.Geocoder();
        //获取搜索框的值
        var  address = document.getElementById("text").value;
        myGeo.getPoint(address,function(point){
            if(point){
                //百度转GCJ-02
                var x_pi = 3.14159265358979324 * 3000.0 / 180.0;
                var x = point.lng - 0.0065;
                var y = point.lat - 0.006;
                var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
                var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
                var gg_lng = z * Math.cos(theta);
                var gg_lat = z * Math.sin(theta);

                //百度GCJ02转web墨卡托84
                var earthRad = 6378137.0;
                point.lng= gg_lng * Math.PI / 180 * earthRad;
                var a = gg_lat * Math.PI / 180;
                point.lat = earthRad / 2 * Math.log((1.0 + Math.sin(a)) / (1.0 - Math.sin(a)));
                console.log(point);
            }
        },"南京市");
        // });
    })
};    

 

posted @ 2019-05-11 15:45 昜木辰deブログ 阅读(...) 评论(...) 编辑 收藏