WGS84转高德地图的SQL逆天写法

 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要在C#中实现WGS84坐标到高德火星坐标的换,可以通过调用高德提供的Web坐标换API来实现。具体步骤如下: 1. 构造请求URL,包括需要换的经纬度坐标、高德提供的开发者key等参数。 2. 发送HTTP请求,获取API返回的JSON格式数据。 3. 解析JSON数据,获取换后的高德火星坐标系坐标。 4. 将高德火星坐标系坐标换为需要的坐标系,例如百度坐标系。 以下是一个示例代码,可以实现WGS84坐标到高德火星坐标系的换: ``` using System; using System.Net; using System.IO; using System.Text; using Newtonsoft.Json.Linq; public class CoordinateConverter { private const string API_URL = "https://restapi.amap.com/v3/assistant/coordinate/convert"; private const string API_KEY = "your_amap_api_key"; public static string WGS84ToAMap(double lng, double lat) { string url = $"{API_URL}?key={API_KEY}&locations={lng},{lat}&coordsys=wgs84"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; request.ContentType = "application/json"; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream, Encoding.UTF8); string result = reader.ReadToEnd(); JObject json = JObject.Parse(result); string locations = json["locations"].ToString(); return locations; } } ``` 调用示例: ``` double lng = 116.397128; double lat = 39.916527; string amapCoord = CoordinateConverter.WGS84ToAMap(lng, lat); Console.WriteLine($"WGS84坐标({lng},{lat})换为高德火星坐标系坐标为:{amapCoord}"); ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xcagy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值