js 经纬度转墨卡托 墨卡托转经纬度

版权声明:本文为博主原创文章,欢迎转载,注明出处。有需要请联系[email protected] https://blog.csdn.net/weixin_42749765/article/details/81986316

实例:

//经纬度转墨卡托
function _getMercator(poi) {//[114.32894, 30.585748]
    var mercator = {};
    var earthRad = 6378137.0;
    // console.log("mercator-poi",poi);
    mercator.x = poi.lng * Math.PI / 180 * earthRad;
    var a = poi.lat * Math.PI / 180;
    mercator.y = earthRad / 2 * Math.log((1.0 + Math.sin(a)) / (1.0 - Math.sin(a)));
    // console.log("mercator",mercator);
    return mercator; //[12727039.383734727, 3579066.6894065146]
}

//墨卡托转经纬度
function _getLngLat(poi){
    var lnglat = {};
    lnglat.lng = poi.x/20037508.34*180;
    var mmy = poi.y/20037508.34*180;
    lnglat.lat = 180/Math.PI*(2*Math.atan(Math.exp(mmy*Math.PI/180))-Math.PI/2);
    return lnglat;
}

猜你喜欢

转载自blog.csdn.net/weixin_42749765/article/details/81986316