Analysis of the Algorithm for Interconversion of Longitude and Latitude of Baidu Gaode Map for iOS Development

First of all, let’s talk about the longitude and latitude. The longitude and latitude of the GPS company is regarded as the earth coordinate system, and the latitude and longitude of the AutoNavi map is the longitude and latitude obtained by the national encryption, which is called the Mars coordinate. The AutoNavi map is the secondary encryption of the Mars coordinates. 

Code when done. 

 

// Baidu to Gaode

-(void)bdToGaodeWithLat:(double)lat andLon:(double)lon

{

    double x_pi = 3.14159265358979324 * 3000.0 / 180.0;

    double x = lon;

    double 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);

    NSLog(@"bd_lon:%f",z * cos(theta) + 0.0065);

    NSLog(@"bd_lat:%f",z * sin(theta) + 0.006);

    //[self gaodeToBdWithLat:(z * sin(theta) + 0.006) andLon:(z * cos(theta) + 0.0065)];

}

 

//Gode to Baidu

-(void)gaodeToBdWithLat:(double)lat andLon:(double)lon

{

    double x_pi = 3.14159265358979324 * 3000.0 / 180.0;

    double x = lon - 0.0065, y = 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);

    NSLog(@"gg_lon:%f",z * cos(theta));

    NSLog(@"gg_lat:%f",z * sin(theta));

    

}

 

Baidu's analysis of the coordinate system:

The international latitude and longitude coordinate standard is WGS-84, and the country must use at least GCJ-02 formulated by the National Bureau of Surveying to encrypt the geographic location for the first time. On this basis, Baidu Coordinate has carried out BD-09 secondary encryption measures to further protect personal privacy. The coordinate system of Baidu's external interface is not the real latitude and longitude collected by GPS, and needs to be converted through the coordinate conversion interface.

 

The following is from Wikipedia

Mars Coordinate System:

It is a national secret plug-in, also called encryption plug-in or offset or SM module. The offset is not linear plus offset, so the offset situation will vary from place to place. The encrypted coordinates are also often referred to as the Mars coordinate system.

 

All electronic maps and navigation equipment need to join the national security plug-in. In the first step, the map company surveys and maps the map. After the survey and mapping is completed, it is sent to the National Bureau of Surveying and Mapping, and the electronic map of the real coordinates is encrypted into "Mars coordinates". Only such a map can be published and released, and then the GPS company can be used. deal with. In the second step, all GPS companies, as long as they need car navigation and electronic maps for navigation, need to add a national security algorithm to the software to encrypt and convert the real coordinate signal read from the COM port into the state required by the country. Confidential coordinates. In this way, the GPS navigator and the navigation electronic map can be completely matched, and the GPS can work normally.

 

The above is basically enough, if not enough, please refer to the following link: http://blog.csdn.net/meegomeego/article/details/39927017

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324722166&siteId=291194637