当前位置:网站首页>GPS original coordinates to Baidu map coordinates (pure C code)
GPS original coordinates to Baidu map coordinates (pure C code)
2022-07-05 14:45:00 【Hua Weiyun】
One 、 Introduction to the environment
GPS Module model : Zhongke microelectronics GPS modular
GPS Output raw data frame :
$GNGGA,114955.000,2842.4158,N,11549.5439,E,1,05,3.8,54.8,M,0.0,M,,*4F$GNGLL,2842.4158,N,11549.5439,E,114955.000,A,A*4D$GPGSA,A,3,10,31,18,,,,,,,,,,5.7,3.8,4.2*37$BDGSA,A,3,07,10,,,,,,,,,,,5.7,3.8,4.2*2A$GPGSV,3,1,10,10,49,184,42,12,16,039,,14,54,341,,18,22,165,23*7B$GPGSV,3,2,10,22,11,318,,25,51,055,,26,24,205,,29,13,110,*7C$GPGSV,3,3,10,31,50,287,36,32,66,018,*7F$BDGSV,1,1,04,03,,,07,05,,,29,07,79,246,33,10,52,232,19*62$GNRMC,114955.000,A,2842.4158,N,11549.5439,E,0.00,44.25,061117,,,A*4D$GNVTG,44.25,T,,M,0.00,N,0.00,K,A*14$GNZDA,114955.000,06,11,2017,00,00*47$GPTXT,01,01,01,ANTENNA OK*35Two 、 Demand is introduced
obtain GPS After the original coordinate data , Want to use Baidu map API The interface directly displays the actual positioning .
The international longitude and latitude coordinate standard is WGS-84, At least the National Survey Bureau must be used in China GCJ- 02, Encrypt the location for the first time .
Baidu coordinates on this basis , the BD-09 Secondary encryption measures , More protection of personal privacy .
The coordinate system of Baidu's external interface is not GPS Collected true classics latitude , It needs to be converted through the coordinate conversion interface .
3、 ... and 、C The language code
The following code is in QtCreator Written in , Code can be ported to any support C Compile and run in the environment of language .
#include <QCoreApplication>#include <QString>#include <QDebug>extern C;{#include <math.h>;}class GPS_Data{public: double lat; // latitude double lng; // longitude QString GPS_Data;};class GPS_Data gps_data;void GPS_ReadUasrtData();#define M_PI 3.14159265358979324double a = 6378245.0;double ee = 0.00669342162296594323;double x_pi = M_PI * 3000.0 / 180.0;double wgs2gcj_lat(double x, double y){ double ret1 = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * sqrt(abs(x)); ret1 += (20.0 * sin(6.0 * x * M_PI) + 20.0 * sin(2.0 * x * M_PI)) * 2.0 / 3.0; ret1 += (20.0 * sin(y * M_PI) + 40.0 * sin(y / 3.0 * M_PI)) * 2.0 / 3.0; ret1 += (160.0 * sin(y / 12.0 * M_PI) + 320 * sin(y * M_PI / 30.0)) * 2.0 / 3.0; return ret1;}double wgs2gcj_lng(double x, double y){ double ret2 = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * sqrt(abs(x)); ret2 += (20.0 *sin(6.0 * x * M_PI) + 20.0 * sin(2.0 * x * M_PI)) * 2.0 / 3.0; ret2 += (20.0 * sin(x * M_PI) + 40.0 * sin(x / 3.0 * M_PI)) * 2.0 / 3.0; ret2 += (150.0 *sin(x / 12.0 * M_PI) + 300.0 * sin(x / 30.0 * M_PI)) * 2.0 / 3.0; return ret2;}void wgs2gcj(double *lat,double *lng){ double dLat = wgs2gcj_lat(*lng - 105.0, *lat - 35.0); double dLon = wgs2gcj_lng(*lng - 105.0, *lat - 35.0); double radLat = *lat / 180.0 * M_PI; double magic = sin(radLat); magic = 1 - ee * magic * magic; double sqrtMagic = sqrt(magic); dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * M_PI); dLon = (dLon * 180.0) / (a / sqrtMagic * cos(radLat) * M_PI); *lat = *lat + dLat; *lng = *lng + dLon;}void gcj2bd(double *lat,double *lng){ double x = *lng, y = *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); *lng = z * cos(theta) + 0.0065; *lat = z * sin(theta) + 0.006;}int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); GPS_ReadUasrtData(); // obtain GPS The original coordinates double lat=gps_data.lat; double lng=gps_data.lng; // Coordinate transformation wgs2gcj(&lat,&lng); gcj2bd(&lat,&lng); // Get the coordinates of Baidu map , It can be displayed directly on Baidu map qDebug()<<" latitude : "<<QString("%1").arg(lat,0,'g',13); qDebug()<<" longitude : "<<QString("%1").arg(lng,0,'g',13); return a.exec();}void GPS_ReadUasrtData(){ /*GPS Original data frame */ gps_data.GPS_Data="$GNGGA,114955.000,2842.4158,N,11549.5439,E,1,05,3.8,54.8,M,0.0,M,,*4F" "$GNGLL,2842.4158,N,11549.5439,E,114955.000,A,A*4D" "$GPGSA,A,3,10,31,18,,,,,,,,,,5.7,3.8,4.2*37" "$BDGSA,A,3,07,10,,,,,,,,,,,5.7,3.8,4.2*2A" " $GPGSV,3,1,10,10,49,184,42,12,16,039,,14,54,341,,18,22,165,23*7B" "$GPGSV,3,2,10,22,11,318,,25,51,055,,26,24,205,,29,13,110,*7C" "$GPGSV,3,3,10,31,50,287,36,32,66,018,*7F" "$BDGSV,1,1,04,03,,,07,05,,,29,07,79,246,33,10,52,232,19*62" "$GNRMC,114955.000,A,2842.4158,N,11549.5439,E,0.00,44.25,061117,,,A*4D" "$GNVTG,44.25,T,,M,0.00,N,0.00,K,A*14" "$GNZDA,114955.000,06,11,2017,00,00*47" "$GPTXT,01,01,01,ANTENNA OK*35"; /* analysis GPS Module data */ //QString lat; // latitude //QString lng; // longitude if(gps_data.GPS_Data.size()>200) { int index=gps_data.GPS_Data.indexOf("$GNGGA"); if(index>=0) { QString text=gps_data.GPS_Data.mid(index); if(text.size()>60) { QString lat=text.section(',',2,2); QString lng=text.section(',',4,4); if(lat.isEmpty()==false && lng.isEmpty()==false) { unsigned int int_data; double s_Longitude,s_latitude; // Convert latitude s_latitude=lat.toDouble(); s_latitude=s_latitude/100; int_data=s_latitude;// Get the latitude integer part s_latitude=s_latitude-int_data;// Get the decimal part of latitude s_latitude=(s_latitude)*100; gps_data.lat=int_data+(s_latitude/60.0); // Get the converted value // Convert longitude s_Longitude=lng.toDouble(); s_Longitude=s_Longitude/100; int_data=s_Longitude;// Get the longitude integer part s_Longitude=s_Longitude-int_data; // Get the longitude fraction s_Longitude=s_Longitude*100; //gai guo le gps_data.lng=int_data+(s_Longitude/60.0); } } } gps_data.GPS_Data.clear(); }}边栏推荐
- CPU design practice - Chapter 4 practical task 2 using blocking technology to solve conflicts caused by related problems
- 实现一个博客系统----使用模板引擎技术
- World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
- 计算中间件 Apache Linkis参数解读
- [detailed explanation of Huawei machine test] character statistics and rearrangement
- How to protect user privacy without password authentication?
- maxcompute有没有能查询 表当前存储容量的大小(kb) 的sql?
- CyCa children's physical etiquette Ningbo training results assessment came to a successful conclusion
- How to open an account of qiniu securities? Is it safe to open an account?
- webRTC SDP mslabel lable
猜你喜欢

申请代码签名证书时如何选择合适的证书品牌?
![[detailed explanation of Huawei machine test] character statistics and rearrangement](/img/0f/972cde8c749e7b53159c9d9975c9f5.png)
[detailed explanation of Huawei machine test] character statistics and rearrangement

日化用品行业智能供应链协同系统解决方案:数智化SCM供应链,为企业转型“加速度”

【leetcode周赛总结】LeetCode第 81 场双周赛(6.25)

两个BI开发,3000多张报表?如何做的到?

Change multiple file names with one click

FR练习题目---简单题

Implement a blog system -- using template engine technology

实现一个博客系统----使用模板引擎技术

PHP - fatal error: allowed memory size of 314572800 bytes exhausted
随机推荐
Chow Tai Fook fulfills the "centenary commitment" and sincerely serves to promote green environmental protection
想问下大家伙,有无是从腾讯云MYSQL同步到其他地方的呀?腾讯云MySQL存到COS上的binlog
Microframe technology won the "cloud tripod Award" at the global Cloud Computing Conference!
js亮瞎你眼的日期选择器
webRTC SDP mslabel lable
Structure - C language
World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
Photoshop plug-in - action related concepts - actions in non loaded execution action files - PS plug-in development
mysql8.0JSON_ Instructions for using contains
Thymeleaf th:classappend属性追加 th:styleappend样式追加 th:data-自定义属性
ASP. Net large takeout ordering system source code (PC version + mobile version + merchant version)
GPS原始坐标转百度地图坐标(纯C代码)
NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读
CYCA少儿形体礼仪 宁波市培训成果考核圆满落幕
[C question set] of Ⅷ
网上电子元器件采购商城:打破采购环节信息不对称难题,赋能企业高效协同管理
Solution of commercial supply chain collaboration platform in household appliance industry: lean supply chain system management, boosting enterprise intelligent manufacturing upgrading
Selection and use of bceloss, crossentropyloss, sigmoid, etc. in pytorch classification
美国费城发生“安全事故” 2名警察遭枪杀
【招聘岗位】基础设施软件开发人员