当前位置: 首页 > article >正文

【.net core】天地图坐标转换为高德地图坐标(WGS84 坐标转 GCJ02 坐标)

 类文件

public static class WGS84ToGCJ02Helper
{// 定义一些常量private const double PI = 3.14159265358979324;private const double A = 6378245.0;private const double EE = 0.00669342162296594323;// 判断坐标是否在中国范围内(不在国内则不进行转换)private static bool OutOfChina(double lng, double lat){return (lng < 72.004 || lng > 137.8347) ||(lat < 0.8293 || lat > 55.8271);}// 转换纬度private static double TransformLat(double x, double y){double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.Sqrt(Math.Abs(x));ret += (20.0 * Math.Sin(6.0 * x * PI) + 20.0 * Math.Sin(2.0 * x * PI)) * 2.0 / 3.0;ret += (20.0 * Math.Sin(y * PI) + 40.0 * Math.Sin(y / 3.0 * PI)) * 2.0 / 3.0;ret += (160.0 * Math.Sin(y / 12.0 * PI) + 320 * Math.Sin(y * PI / 30.0)) * 2.0 / 3.0;return ret;}// 转换经度private static double TransformLng(double x, double y){double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.Sqrt(Math.Abs(x));ret += (20.0 * Math.Sin(6.0 * x * PI) + 20.0 * Math.Sin(2.0 * x * PI)) * 2.0 / 3.0;ret += (20.0 * Math.Sin(x * PI) + 40.0 * Math.Sin(x / 3.0 * PI)) * 2.0 / 3.0;ret += (150.0 * Math.Sin(x / 12.0 * PI) + 300.0 * Math.Sin(x / 30.0 * PI)) * 2.0 / 3.0;return ret;}// WGS84 转 GCJ02public static (double lng, double lat) Wgs84ToGcj02(double wgsLng, double wgsLat){if (OutOfChina(wgsLng, wgsLat)){return (wgsLng, wgsLat);}double dLat = TransformLat(wgsLng - 105.0, wgsLat - 35.0);double dLng = TransformLng(wgsLng - 105.0, wgsLat - 35.0);double radLat = wgsLat / 180.0 * PI;double magic = Math.Sin(radLat);magic = 1 - EE * magic * magic;double sqrtMagic = Math.Sqrt(magic);dLat = (dLat * 180.0) / ((A * (1 - EE)) / (magic * sqrtMagic) * PI);dLng = (dLng * 180.0) / (A / sqrtMagic * Math.Cos(radLat) * PI);double mgLat = wgsLat + dLat;double mgLng = wgsLng + dLng;return (mgLng, mgLat);}
}

调用

        // 示例:北京天安门的 WGS84 坐标double wgsLng = 116.397228;double wgsLat = 39.907501;// 转换为 GCJ02 坐标var gcjCoord = WGS84ToGCJ02Helper.Wgs84ToGcj02(wgsLng, wgsLat);Console.WriteLine($"WGS84 坐标: ({wgsLng}, {wgsLat})");Console.WriteLine($"GCJ02 坐标: ({gcjCoord.lng}, {gcjCoord.lat})");

http://www.lryc.cn/news/2404623.html

相关文章:

  • Linux操作系统故障应急场景及对应排查方法
  • 电镀机的阳极是什么材质?
  • vscode调试deepspeed的方法之一(无需调整脚本)
  • 神经网络-Day44
  • 创客匠人:如何通过精准定位实现创始人IP打造与知识变现
  • Codeforces Round 509 (Div. 2) C. Coffee Break
  • 榕壹云健身预约系统:多门店管理的数字化解决方案(ThinkPHP+MySQL+UniApp实现)
  • QUIC——UDP实现可靠性传输
  • 提高Python编程效率的工具推荐
  • React Native图片预加载:让你的应用图片预览像德芙一样丝滑
  • 快速上手shell脚本运行流程控制
  • 10.Linux进程信号
  • Python 函数全攻略:函数基础
  • 机器学习基础(四) 决策树
  • DDPM优化目标公式推导
  • CentOS 7如何编译安装升级gcc至7.5版本?
  • 为什么React列表项需要key?(React key)(稳定的唯一标识key有助于React虚拟DOM优化重绘大型列表)
  • Playwright自动化测试全栈指南:从基础到企业级实践(2025终极版)
  • 飞牛云一键设置动态域名+ipv6内网直通访问内网的ssh服务-家庭云计算专家
  • 虚实共生时代的情感重构:AI 恋爱陪伴的崛起、困局与明日图景
  • 嵌入式面试高频(5)!!!C++语言(嵌入式八股文,嵌入式面经)
  • C++动态规划-线性DP
  • Java高级 | 【实验七】Springboot 过滤器和拦截器
  • es地理信息索引的类型以及geo_point‌和geo_hash的关系
  • 深入理解 Spring IOC:从概念到实践
  • Vue解决开发环境 Ajax 跨域问题
  • 行为设计模式之Command (命令)
  • 若依添加添加监听容器配置(删除键,键过期)
  • NeRF 技术深度解析:原理、局限与前沿应用探索(AI+3D 产品经理笔记 S2E04)
  • ROS2,工作空间中新建了一个python脚本,需要之后作为节点运行。告诉我步骤?