当前位置:网站首页>Method of converting GPS coordinates to Baidu map coordinates
Method of converting GPS coordinates to Baidu map coordinates
2022-07-03 06:03:00 【UU_ Yang】
from :GPS The method of converting coordinates to Baidu map coordinates - Programmer base
First of all, I need to know GPS The coordinate system of .GPS Coordinate system follows WGS-84 standard , By this standard ,GPS The chip can send different packet formats . According to the difference of its data frame header ,GPS The data can be classified as GPGGA、GPGSA、GPGSV、GPRMC etc. . These frame headers identify the composition of subsequent intra frame data . Usually , The positioning data we are concerned about, such as longitude and latitude 、 Speed 、 Time, etc. can be from GPRMC Get in the frame .
I won't explain the format of specific frames this time , You can easily find it on the Internet , The format of data frame can also be found in the interface document of the general chip . By reading GPRMC package , We can get something similar to “3040.8639,N,10405.7573,E” The location data of , Its field meaning can be found in the document . The result of my analysis here is : North latitude 30°40.8639', East longitude 104°5.7573'.
After getting these two data , We can try to locate it on the map , We found that most map locations use decimal coordinates . Here we need to talk about how to put a GPS Raw data , Data converted to decimal form .
give an example :106°14'15" Transformation
Because degrees, minutes and seconds are in hexadecimal
So it can be converted in this way :
15/60=0.25 branch
(14+0.25)/60=0.2375 degree
106+0.2375=106.2375 degree
So the end result is 106.2375°
After this conversion , My position coordinates 【 North latitude 30°40.8639', East longitude 104°5.7573'】 It can become 【30.681065N,104.095955E】( This is WGS-84 Coordinates of ) This look . This coordinate is GPS Physical positioning of , According to international standards , This coordinate needs to be GCJ-02 Offset conversion , The converted coordinates can be in google Map 、 Gould map 、 And positioning on Tencent map ( The above three companies follow GCJ-02 encryption ). As for why this should be done , It's because the coordinates are encrypted . because GCJ-02 It is an irreversible transformation .
You zhuxun is posted here WGS-84 The standard is converted to GCJ-02 Of C++ Source code :
const double pi = 3.14159265358979324;
//
// Krasovsky 1940
//
// a = 6378245.0, 1/f = 298.3
// b = a * (1 - f)
// ee = (a^2 - b^2) / a^2;
const double a = 6378245.0;
const double ee = 0.00669342162296594323;
static bool outOfChina(double lat, double lon)
{
if (lon < 72.004 || lon > 137.8347)
return true;
if (lat < 0.8293 || lat > 55.8271)
return true;
return false;
}
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 * sqrt(abs(x));
ret += (20.0 * sin(6.0 * x * pi) + 20.0 * sin(2.0 * x * pi)) * 2.0 / 3.0;
ret += (20.0 * sin(y * pi) + 40.0 * sin(y / 3.0 * pi)) * 2.0 / 3.0;
ret += (160.0 * sin(y / 12.0 * pi) + 320 * sin(y * pi / 30.0)) * 2.0 / 3.0;
return ret;
}
static double transformLon(double x, double y)
{
double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * sqrt(abs(x));
ret += (20.0 * sin(6.0 * x * pi) + 20.0 * sin(2.0 * x * pi)) * 2.0 / 3.0;
ret += (20.0 * sin(x * pi) + 40.0 * sin(x / 3.0 * pi)) * 2.0 / 3.0;
ret += (150.0 * sin(x / 12.0 * pi) + 300.0 * sin(x / 30.0 * pi)) * 2.0 / 3.0;
return ret;
}
/*
Parameters
wgLat:WGS-84 latitude wgLon:WGS-84 longitude
Return value :
mgLat:GCJ-02 latitude mgLon:GCJ-02 longitude
*/
void gps_transform( double wgLat, double wgLon, double& mgLat, double& mgLon)
{
if (outOfChina(wgLat, wgLon)) {
mgLat = wgLat;
mgLon = wgLon;
return;
}
double dLat = transformLat(wgLon - 105.0, wgLat - 35.0);
double dLon = transformLon(wgLon - 105.0, wgLat - 35.0);
double radLat = wgLat / 180.0 * pi; double magic = sin(radLat);
magic = 1 - ee * magic * magic; double sqrtMagic = sqrt(magic);
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);
dLon = (dLon * 180.0) / (a / sqrtMagic * cos(radLat) * pi);
mgLat = wgLat + dLat; mgLon = wgLon + dLon;
} After the above conversion , Our coordinates can be followed GCJ-02 The standard map has been deleted , Here is a more useful test Location URL :http://www.gpsspg.com/maps.htm
Baidu map is a little special , It's in GCJ-02 On this basis, another encryption is carried out , Baidu calls this encryption standard BD-09, But this encryption is not publicly available . But the omnipotent network and omnipotent netizens will always have a way to solve this kind of problem . Here I will post a feasible conversion method , After testing , The positioning is very accurate .
#include <math.h>
const double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
// take GCJ-02 The coordinates are converted to BD-09 coordinate
void bd_encrypt(double gg_lat, double gg_lon, double &bd_lat, double &bd_lon)
{
double x = gg_lon, y = gg_lat;
double z = sqrt(x * x + y * y) + 0.00002 * sin(y * x_pi);
double theta = atan2(y, x) + 0.000003 * cos(x * x_pi);
bd_lon = z * cos(theta) + 0.0065;
bd_lat = z * sin(theta) + 0.006;
}
void bd_decrypt(double bd_lat, double bd_lon, double &gg_lat, double &gg_lon)
{
double x = bd_lon - 0.0065, y = bd_lat - 0.006;
double z = sqrt(x * x + y * y) - 0.00002 * sin(y * x_pi);
double theta = atan2(y, x) - 0.000003 * cos(x * x_pi);
gg_lon = z * cos(theta);
gg_lat = z * sin(theta);
} such , Our coordinates can also be accurately located on Baidu map , They were filled with joy ~~
In addition, a legend that can easily explain why coordinates need to be converted is pasted , So that we can understand :
International conversion practice :
Baidu's approach :
It also explains , Why? GPS The reason why coordinates need to be converted . Thanks to the people who contributed these materials to the Internet !
Reference resources :
http://m.blog.csdn.net/blog/wildboy2001/39497681
http://www.haodaima.net/art/2441684
http://www.gpsspg.com/maps.htm
http://wenda.haosou.com/q/1365472754066079
http://www.geekcome.com/content-10-1464-1.html
边栏推荐
- Loss function in pytorch multi classification
- Apt update and apt upgrade commands - what is the difference?
- How to create and configure ZABBIX
- Yum is too slow to bear? That's because you didn't do it
- BeanDefinitionRegistryPostProcessor
- Understand the first prediction stage of yolov1
- Solve the problem that Anaconda environment cannot be accessed in PowerShell
- Btrfs and ext4 - features, strengths and weaknesses
- Qt读写Excel--QXlsx插入图表5
- [teacher Zhao Yuqiang] kubernetes' probe
猜你喜欢

Convolution operation in convolution neural network CNN

Deep learning, thinking from one dimensional input to multi-dimensional feature input

PHP notes are super detailed!!!
![[escape character] [full of dry goods] super detailed explanation + code illustration!](/img/33/ec5a5e11bfd43f53f2767a9a0f0cc9.jpg)
[escape character] [full of dry goods] super detailed explanation + code illustration!

Solve the 1251 client does not support authentication protocol error of Navicat for MySQL connection MySQL 8.0.11

pytorch 多分类中的损失函数

Solve the problem of automatic disconnection of SecureCRT timeout connection

智牛股项目--05

CKA certification notes - CKA certification experience post

Capacity expansion mechanism of map
随机推荐
深度学习,从一维特性输入到多维特征输入引发的思考
Ext4 vs XFS -- which file system should you use
Kubernetes resource object introduction and common commands (V) - (configmap)
88. 合并两个有序数组
Today, many CTOs were killed because they didn't achieve business
How to create your own repository for software packages on Debian
[teacher Zhao Yuqiang] the most detailed introduction to PostgreSQL architecture in history
JDBC connection database steps
Core principles and source code analysis of disruptor
SVN分支管理
Crontab command usage
70 shell script interview questions and answers
从小数据量分库分表 MySQL 合并迁移数据到 TiDB
Clickhouse learning notes (I): Clickhouse installation, data type, table engine, SQL operation
Kubernetes notes (10) kubernetes Monitoring & debugging
[teacher Zhao Yuqiang] calculate aggregation using MapReduce in mongodb
Yum is too slow to bear? That's because you didn't do it
Es 2022 officially released! What are the new features?
How to create and configure ZABBIX
Jetson AgX Orin platform porting ar0233 gw5200 max9295 camera driver