1. 程式人生 > >經緯度和墨卡托坐標相互轉換

經緯度和墨卡托坐標相互轉換

double tor pos brush ble clas body class sha

//經緯度轉墨卡托
public void loc_to_mercator(double lon, double lat,ref double miX,ref double minY)
        {
            double x = lon;
            double y = Math.Log(Math.Tan((lat / 180 * Math.PI + Math.PI / 2) / 2)) * 180 / Math.PI;
            miX = x * 20037508.3427892 / 180;
            minY = y * 20037508.3427892 / 180;
        }

//摩卡脫轉經緯度
public void mercator_to_loc(double mercator_x, double mercator_y, ref double lon, ref double lat)
        {
            double x = mercator_x / 20037508.3427892 * 180;
            double y = mercator_y / 20037508.3427892 * 180;
            lon = x;
            lat = 180 / Math.PI * (2 * Math.Atan(Math.Exp(y * Math.PI / 180)) - Math.PI / 2);
        }

  

經緯度和墨卡托坐標相互轉換