美文网首页
墨卡托与经纬度互转

墨卡托与经纬度互转

作者: zhuyx0304 | 来源:发表于2024-05-21 09:01 被阅读0次
export function mercatorTolonlat(xx, yy) {
  let lonlat = {};

  let x = (xx / 20037508.34) * 180;
  let y = (yy / 20037508.34) * 180;

  y =
    (180 / Math.PI) *
    (2 * Math.atan(Math.exp((y * Math.PI) / 180)) - Math.PI / 2);

  lonlat.lon = x;
  lonlat.lat = y;

  return lonlat;
}

export function lonlatToMercator(lon, lat) {
  var mercator = {};

  let x = (lon * 20037508.34) / 180;
  let y = Math.log(Math.tan(((90 + lat) * Math.PI) / 360)) / (Math.PI / 180);

  y = (y * 20037508.34) / 180;

  mercator.x = x;
  mercator.y = y;

  return mercator;
}

相关文章

网友评论

      本文标题:墨卡托与经纬度互转

      本文链接:https://www.haomeiwen.com/subject/pwtafjtx.html