当前位置:网站首页>C Baidu map, Gaode map, Google map (GPS) longitude and latitude conversion
C Baidu map, Gaode map, Google map (GPS) longitude and latitude conversion
2022-07-02 08:46:00 【Qingshan blog】
using System;
namespace PhotoHelper
{
/// <summary>
/// Position coordinate conversion class
/// WGS-84: It's an international standard ,GPS coordinate (Google Earth Use 、 perhaps GPS modular )
/// GCJ-02: Chinese standard of coordinate migration ,Google Map、 Gao de 、 Tencent uses
/// BD-09: Baidu coordinate offset standard ,Baidu Map Use
/// </summary>
public class LocationUtil
{
public const double Pi = 3.14159265358979324 * 3000.0 / 180.0;
private static readonly double pi = 3.14159265358979324;
private static readonly double a = 6378245.0;
private static readonly double ee = 0.00669342162296594323;
/// <summary>
/// international standard -> Baidu standard (gps Coordinate conversion to Baidu coordinate , Before the decimal point 4 Position is the exact coordinate )
/// </summary>
/// <param name="lat"> latitude </param>
/// <param name="lon"> longitude </param>
/// <returns></returns>
public static double[] Wgs2Bd(double lat, double lon)
{
var wgs2Gcj = Wgs2Gcj(lat, lon);
var gcj2Bd = Gcj2Bd(wgs2Gcj[0], wgs2Gcj[1]);
return gcj2Bd;
}
public static double[] Gcj2Bd(double lat, double lon)
{
double x = lon, y = lat;
var z = Math.Sqrt(x * x + y * y) + 0.00002 * Math.Sin(y * Pi);
var theta = Math.Atan2(y, x) + 0.000003 * Math.Cos(x * Pi);
var cos = z * Math.Cos(theta) + 0.0065;
var sin = z * Math.Sin(theta) + 0.006;
return new[] { sin, cos };
}
public static double[] Bd2Gcj(double lat, double lon)
{
double x = lon - 0.0065, y = lat - 0.006;
var z = Math.Sqrt(x * x + y * y) - 0.00002 * Math.Sin(y * Pi);
var theta = Math.Atan2(y, x) - 0.000003 * Math.Cos(x * Pi);
var cos = z * Math.Cos(theta);
var sin = z * Math.Sin(theta);
return new[] { sin, cos };
}
public static double[] Wgs2Gcj(double lat, double lon)
{
var dLat = TransformLat(lon - 105.0, lat - 35.0);
var dLon = TransformLon(lon - 105.0, lat - 35.0);
var radLat = lat / 180.0 * pi;
var magic = Math.Sin(radLat);
magic = 1 - ee * magic * magic;
var sqrtMagic = Math.Sqrt(magic);
dLat = dLat * 180.0 / (a * (1 - ee) / (magic * sqrtMagic) * pi);
dLon = dLon * 180.0 / (a / sqrtMagic * Math.Cos(radLat) * pi);
var mgLat = lat + dLat;
var mgLon = lon + dLon;
double[] loc = { mgLat, mgLon };
return loc;
}
private static double TransformLat(double lat, double lon)
{
var ret = -100.0 + 2.0 * lat + 3.0 * lon + 0.2 * lon * lon + 0.1 * lat * lon + 0.2 * Math.Sqrt(Math.Abs(lat));
ret += (20.0 * Math.Sin(6.0 * lat * pi) + 20.0 * Math.Sin(2.0 * lat * pi)) * 2.0 / 3.0;
ret += (20.0 * Math.Sin(lon * pi) + 40.0 * Math.Sin(lon / 3.0 * pi)) * 2.0 / 3.0;
ret += (160.0 * Math.Sin(lon / 12.0 * pi) + 320 * Math.Sin(lon * pi / 30.0)) * 2.0 / 3.0;
return ret;
}
private static double TransformLon(double lat, double lon)
{
var ret = 300.0 + lat + 2.0 * lon + 0.1 * lat * lat + 0.1 * lat * lon + 0.1 * Math.Sqrt(Math.Abs(lat));
ret += (20.0 * Math.Sin(6.0 * lat * pi) + 20.0 * Math.Sin(2.0 * lat * pi)) * 2.0 / 3.0;
ret += (20.0 * Math.Sin(lat * pi) + 40.0 * Math.Sin(lat / 3.0 * pi)) * 2.0 / 3.0;
ret += (150.0 * Math.Sin(lat / 12.0 * pi) + 300.0 * Math.Sin(lat / 30.0 * pi)) * 2.0 / 3.0;
return ret;
}
}
}边栏推荐
- PCL calculates the intersection of three mutually nonparallel planes
- Kubernetes deploys Loki logging system
- Pointer initialization
- Openshift build image
- Driving test Baodian and its spokesperson Huang Bo appeared together to call for safe and civilized travel
- Jumping | Blue Bridge Cup
- Aneng logistics' share price hit a new low: the market value evaporated by nearly 10 billion yuan, and it's useless for chairman Wang Yongjun to increase his holdings
- Minecraft群组服开服
- The best blog to explain the basics of compilation (share)
- OpenShift 容器平台社区版 OKD 4.10.0部署
猜你喜欢

c语言自定义类型——结构体,位段(匿名结构体,结构体的自引用,结构体的内存对齐)

方法递归(斐波那契数列,青蛙跳台阶,汉诺塔问题)

Flex layout

小米电视不能访问电脑共享文件的解决方案

Minecraft空岛服开服

Driving test Baodian and its spokesperson Huang Bo appeared together to call for safe and civilized travel

KubeSphere 虚拟化 KSV 安装体验
![[blackmail virus data recovery] suffix Rook3 blackmail virus](/img/46/debc848d17767d021f3f41924cccfe.jpg)
[blackmail virus data recovery] suffix Rook3 blackmail virus

整理秒杀系统的面试必备!!!

Chrome debugging
随机推荐
Application of kotlin - higher order function
HCIA - data link layer
[untitled]
Linked list classic interview questions (reverse the linked list, middle node, penultimate node, merge and split the linked list, and delete duplicate nodes)
文件上传-upload-labs
Function ‘ngram‘ is not defined
方法递归(斐波那契数列,青蛙跳台阶,汉诺塔问题)
Qt QTimer类
Illegal use of crawlers, an Internet company was terminated, the police came to the door, and 23 people were taken away
ARP及ARP欺骗
C language replaces spaces in strings with%20
Honeypot attack and defense drill landing application scheme
sqli-labs第12关
sqli-labs(POST类型注入)
汉诺塔问题的求解与分析
Use the kaggle training model and download your own training model
判断是否是数独
Sqli labs (post type injection)
用数字 5,5,5,1 ,进行四则运算,每个数字当且仅当用一次,要求运算结果值为 24
Minecraft群組服開服