WGS84转高德地图的SQL逆天写法
兼容MYSQL和PGSQL
SELECT
-- 经度
xlongitude +
(((300.0 + (xlongitude - 105.0) + 2.0 * (ylatitude - 35.0) + 0.1 * (xlongitude - 105.0) * (xlongitude - 105.0) +
0.1 * (xlongitude - 105.0) * (ylatitude - 35.0) + 0.1 * sqrt(abs((xlongitude - 105.0))) +
(20.0 * sin(6.0 * (xlongitude - 105.0) * 3.1415926535897932384626) + 20.0 * sin(2.0 * (xlongitude - 105.0) * 3.1415926535897932384626)) * 2.0 / 3.0 +
(20.0 * sin((xlongitude - 105.0) * 3.1415926535897932384626) + 40.0 * sin((xlongitude - 105.0) / 3.0 * 3.1415926535897932384626)) * 2.0 / 3.0 +
(150.0 * sin((xlongitude - 105.0) / 12.0 * 3.1415926535897932384626) + 300.0 * sin((xlongitude - 105.0) / 30.0 * 3.1415926535897932384626)) * 2.0 / 3.0) * 180.0) / (6378245.0 / (SQRT(1 - 0.00669342162296594323 * sin((ylatitude) / 180.0 * 3.1415926535897932384626) * sin((ylatitude) /180.0 * 3.1415926535897932384626))) * COS((ylatitude) / 180.0 * 3.1415926535897932384626) * 3.1415926535897932384626)) AS lon,
-- 纬度
ylatitude +
((-100.0 + 2.0 * (xlongitude - 105.0) + 3.0 * (ylatitude - 35.0) + 0.2 * (ylatitude - 35.0) * (ylatitude - 35.0) +
0.1 * (xlongitude - 105.0) * (ylatitude - 35.0) + 0.2 * sqrt(abs(xlongitude - 105.0)) +
(20.0 * sin(6.0 * (xlongitude - 105.0) * 3.1415926535897932384626) + 20.0 * sin(2.0 * (xlongitude - 105.0) * 3.1415926535897932384626)) * 2.0 /3.0 +
(20.0 * sin((ylatitude - 35.0) * 3.1415926535897932384626) + 40.0 * sin((ylatitude - 35.0) / 3.0 * 3.1415926535897932384626)) * 2.0 / 3.0 +
(160.0 * sin((ylatitude - 35.0) / 12.0 * 3.1415926535897932384626) + 320 * sin((ylatitude - 35.0) * 3.1415926535897932384626 / 30.0)) * 2.0 / 3.0 ) * 180) / ((6378245.0 * (1 - 0.00669342162296594323)) / ((1 - 0.00669342162296594323 * sin((ylatitude) /180.0 * 3.1415926535897932384626) * sin((ylatitude) /180.0 * 3.1415926535897932384626)) * (SQRT(1 - 0.00669342162296594323 * sin((ylatitude) /180.0 * 3.1415926535897932384626) * sin((ylatitude) /180.0 * 3.1415926535897932384626)))) * 3.1415926535897932384626) AS lat