First you need to know the GPS coordinate system. The GPS coordinate system follows the WGS-84 standard, under which the GPS chip can emit different packet formats. The GPS data can be classified into Gpgga, Gpgsa, GPGSV, GPRMC and so on, according to the different frame-frame head of the data. These frame headers identify the structure of the data in subsequent frames. Usually, we are concerned about the location of data such as latitude and longitude, speed, time and so can be obtained from the GPRMC frame.
In the time I do not explain the specific frame format, on the internet can be easily found, but also the total chip supporting the interface document to find the format of the data frame. By interpreting the GPRMC package, we can get position data similar to "3040.8639,n,10405.7573,e", whose field meaning can be found in the document. Here I resolved the result is: Northern latitude 30°40.8639 ', East longitude 104°5.7573 '.
After getting these two data, we can try to locate on the map, we found that most of the map positioning with the decimal form of coordinates. Here we need to talk about how to convert a GPS raw data into a decimal form of data.
Example: Conversion of 106°14 ' 15 '
Because it's six decimal seconds.
So you can convert this way:
15/60=0.25 points
(14+0.25)/60=0.2375 degree
106+0.2375=106.2375 degree
So the final result is 106.2375°.
After this transformation, my position coordinates "north latitude 30°40.8639 ', East longitude 104°5.7573 '" can become "30.681065n,104.095955e" (this is WGS-84 coordinates) this appearance. This coordinates is the physical positioning of the GPS, according to international standards, the need for this coordinate GCJ-02 offset conversion, the transformation of the coordinates can be in Google Maps, the gold map, as well as Tencent map positioning (the above three follow GCJ-02 encryption). The reason for this is because of the encryption coordinates. Because GCJ-02 are irreversible conversions.
Here is posted by the quasi-search WGS-84 standard conversion to GCJ-02 C + + Source:
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) + pi/30.0 (y *)) * 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 * p)i) + 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; }/* parameter 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 conversion, our coordinates can be in accordance with the GCJ-02 standard map deletion location, here gives everyone a more useful test location of the URL: http://www.gpsspg.com/maps.htm
Baidu Map Some special, it GCJ-02 on the basis of a second encryption, Baidu, the encryption standard called BD-09, but this encryption is not public. But the omnipotent network and the omnipotent netizens always have the means to solve such problems. Here I put out a feasible conversion method, after testing, positioning is very accurate.
#include <math.h>
const DOUBLE X_PI = 3.14159265358979324 * 3000.0/180.0;
Converts GCJ-02 coordinates to BD-09 coordinate
void Bd_encrypt (double Gg_lat, double Gg_lon, double &bd_lat, double &bd_lon)
{ c4/>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.00 and 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);
In this way, our coordinates can also be accurately positioned on the Baidu map, filled with joy ~ ~
In addition to a more easily explain why coordinates need to be converted to the legend, so as to facilitate understanding:
International Common Conversion Practices:
Baidu's approach:
This also explains why GPS coordinates need to be converted for reasons. Thank you for contributing this information to people online.
Reference:
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