Analysis of the Mars coordinate system and the Earth coordinate system developed by iOS, and the Earth in the ios Mars Coordinate System

Source: Internet
Author: User

Analysis of the Mars coordinate system and the Earth coordinate system developed by iOS, and the Earth in the ios Mars Coordinate System

Analysis of the Mars coordinate system and the Earth coordinate system developed by iOS.

During the development process, a problem occurs: Android and iOS send the same latitude and longitude to the backend, but the hotels in the backend are indeed different in distance sorting.

Cause: Android uses AMAP for positioning. the longitude and latitude of direct positioning are the Mars coordinate system, while iOS uses the positioning system that comes with Apple. The positioning coordinates are the earth coordinate system and are not converted.

Solution: using the method provided by the architecture group, the error is found to be inaccurate. The difference is about 500 ~ M distance, failed to try.

Another method: (provided by AMAP)

CLLocationCoordinate2D amapcoord = AMapCoordinateConvert (CLLocationCoordinate2DMake (39.989612, 116.480972), AMapCoordinateType );

// Convert the earth coordinate system to the Mars Coordinate System

Self. currentLocation = AMapCoordinateConvert (CLLocationCoordinate2DMake ([TNLocationManager sharedInstance]. lat, [TNLocationManager sharedInstance]. lng), AMapCoordinateTypeGPS );

The effect is better. The gap is within 1 MB. The architecture group re-modifies the conversion algorithm :)

The principle is as follows: the Security Bureau has developed a system that can convert the actual coordinates into virtual coordinates. All digital maps sold in China must use this system for coordinate conversion before they can be listed. This is a production phase. This electronic map is called a map of Mars. During use, the GPS terminal device must integrate the encryption algorithm provided by the Security Bureau (the integration is completed by the Security Bureau) to convert the coordinates obtained from the GPS satellite into virtual coordinates, then, you can search for the map on the Mars map, so that the map matching is completed in the Mars coordinate system. Therefore, Baidu, AMAP, and other map positioning methods are usually several hundred meters away.

Glossary:

Earth coordinate: refers to the WGS84 Coordinate System

Mars coordinates: coordinates after the human offset using the national security plug-in

Earth map: refers to the objective and real map corresponding to the Earth coordinates.

Mars map: refers to the map corresponding to the Mars coordinate after the encrypted offset

Coordinate System Conversion Algorithm

1. GCJ-02 (Mars Coordinate System) and BD-09 Conversion

[Cpp] view plaincopy

// GCJ-02 coordinate conversion to BD-09 Coordinate

+ (CLLocationCoordinate2D) MarsGS2BaiduGS :( CLLocationCoordinate2D) coordinate

{

Doublex_pi = PI * 3000.0/180.0;

Doublex = coordinate. longpolling, y = coordinate. latitude;

Doublez = sqrt (x * x + y * y) + 0.00002 * sin (y * x_pi );

Doubletheta = atan2 (y, x) + 0.000003 * cos (x * x_pi );

Doublebd_lon = z * cos (theta) + 0.0065;

Doublebd_lat = z * sin (theta) + 0.006;

ReturnCLLocationCoordinate2DMake (bd_lat, bd_lon );

}

// BD-09 coordinate conversion to GCJ-02 Coordinate

+ (CLLocationCoordinate2D) BaiduGS2MarsGS :( CLLocationCoordinate2D) coordinate

{

Doublex_pi = PI * 3000.0/180.0;

Doublex = coordinate. longbench-0.0065, y = coordinate. latitude-0.006;

Doublez = sqrt (x * x + y * y)-0.00002 * sin (y * x_pi );

Doubletheta = atan2 (y, x)-0.000003 * cos (x * x_pi );

Doublegg_lon = z * cos (theta );

Doublegg_lat = z * sin (theta );

ReturnCLLocationCoordinate2DMake (gg_lat, gg_lon );

}

2WGS-84 (Earth Coordinate System) and BD-09 (Baidu Coordinate System) Conversion

[Cpp] view plaincopy

// WGS-84 coordinate conversion to BD-09 Coordinate

+ (CLLocationCoordinate2D) WorldGS2BaiduGS :( CLLocationCoordinate2D) coordinate

{

CLLocationCoordinate2Dmars = [ALDGeocoderWorldGS2MarsGS: coordinate];

CLLocationCoordinate2Dbaidu = [ALDGeocoderMarsGS2BaiduGS: mars];

Returnbaidu;

}

// BD-09 coordinate conversion to WGS-84 Coordinate

+ (CLLocationCoordinate2D) BaiduGS2WorldGS :( CLLocationCoordinate2D) coordinate

{

CLLocationCoordinate2Dmars = [ALDGeocoderBaiduGS2MarsGS: coordinate];

CLLocationCoordinate2Dworld = [ALDGeocoderMarsGS2WorldGS: mars];

Returnworld;

}

3. Coordinate Transformation between WGS-84 and sogou

[Cpp] view plaincopy

// Convert the WGS-84 coordinates to Sogou coordinates

+ (CLLocationCoordinate2D) WorldGS2SogouGS :( CLLocationCoordinate2D) coordinate

{

Constdoubleee = 0.082271854224939184;

Doublelon = coordinate. longpolling;

Doublelat = coordinate. latitude;

Doubledlon = [ALDGeocoderrad: CLIP (lon,-360,360)];

Doubledlat = [ALDGeocoderrad: CLIP (lat,-90,90)];

Dlon = 6378206.4 * dlon;

Doublesinphi = sin (dlat );

Doubletemp1, temp2;

If (temp1 = 1.0 + sinphi) = 0.0 ){

Dlat =-1000000000;

} Elseif (temp2 = 1.0-sinphi) = 0.0 ){

Dlat = 1000000000;

} Else {

Doubleesinphi = ee * sinphi;

Dlat = 3189103.2000000002 * log (temp1/temp2) * pow (1.0-esinphi)/(1.0 + esinphi), ee ));

}

ReturnCLLocationCoordinate2DMake (dlat, dlon );

}

// Sogou coordinate conversion to WGS-84 Coordinate

+ (CLLocationCoordinate2D) SogouGS2WorldGS :( CLLocationCoordinate2D) coordinate

{

Constdoubleee = 1.5707963267948966;

Constdoubleaa = 0.0033938814110493522;

Doublelon = coordinate. longpolling;

Doublelat = coordinate. latitude;

Doubledlon = lon/6378206.4;

Doubletemp =-lat/6378206.4;

Doublechi;

If (temp <-307 ){

Chi = ee;

} Elseif (temp & gt; 308 ){

Chi =-ee;

} Else {

Chi = ee-2 * atan (exp (temp ));

}

Doublechi2 = 2 * chi;

Doublecoschi2 = cos (chi2 );

Doubledlat = chi + sin (chi2) * (aa + coschi2 * (cost-005 + coschi2 * (7.2964821399246009e-008 + coschi2 * 4.4551470401894685E-010 )));

Doublerlon = CLIP ([ALDGeocoderdeg: dlon],-360,360 );

Doublerlat = CLIP ([ALDGeocoderdeg: dlat],-90 );

ReturnCLLocationCoordinate2DMake (rlat, rlon );

}

4. Coordinate Transformation between the Mars coordinate and the Earth Coordinate

[Cpp] view plaincopy

// WorldGeodeticSystem ==> MarsGeodeticSystem

+ (CLLocationCoordinate2D) WorldGS2MarsGS :( CLLocationCoordinate2D) coordinate

{

// A = 6378245.0, 1/f = 298.3

// B = a * (1-f)

// Ee = (a ^ 2-b ^ 2)/a ^ 2;

Constdoublea = 6378245.0;

Constdoubleee = 0.00669342162296594323;

If (outOfChina (coordinate. latitude, coordinate. longpolling ))

{

Returncoordinate;

}

DoublewgLat = coordinate. latitude;

DoublewgLon = coordinate. longpolling;

DoubledLat = transformLat (wgLon-105.0, wgLat-35.0 );

DoubledLon = transformLon (wgLon-105.0, wgLat-35.0 );

DoubleradLat = wgLat/180.0 * PI;

Doublemagic = sin (radLat );

Magic = 1-ee * magic;

DoublesqrtMagic = sqrt (magic );

DLat = (dLat * 180.0)/(a * (1-ee)/(magic * sqrtMagic) * PI );

DLon = (dLon * 180.0)/(a/sqrtMagic * cos (radLat) * PI );

ReturnCLLocationCoordinate2DMake (wgLat + dLat, wgLon + dLon );

}

// MarsGeodeticSystem ==> WorldGeodeticSystem

+ (CLLocationCoordinate2D) MarsGS2WorldGS :( CLLocationCoordinate2D) coordinate

{

DoublegLat = coordinate. latitude;

DoublegLon = coordinate. longpolling;

CLLocationCoordinate2DmarsCoor = [ALDGeocoderWorldGS2MarsGS: coordinate];

DoubledLat = marsCoor. latitude-gLat;

DoubledLon = marsCoor. longbench-gLon;

ReturnCLLocationCoordinate2DMake (gLat-dLat, gLon-dLon );

}

Coordinate Conversion between 5WGS-84 and mocato

[Cpp] view plaincopy

// Convert the WGS-84 coordinates to Mercato coordinates

+ (CLLocationCoordinate2D) WorldGS2Mercator :( CLLocationCoordinate2D) coordinate

{

Doublelon = coordinate. long1_* 20037508.34/180;

Doublelat = log (tan (90 + coordinate. latitude) * M_PI/360)/(M_PI/180 );

Lat = lat * 20037508.34/180;

ReturnCLLocationCoordinate2DMake (lat, lon );

}

// Mercato coordinates are converted into WGS-84 coordinates

+ (CLLocationCoordinate2D) Mercator2WorldGS :( CLLocationCoordinate2D) mercator

{

Doublelon = mercator. longpolling/20037508.34*180;

Doublelat = mercator. latitude/20037508.34*180;

Lat = 180/M_PI * (2 * atan (exp (lat * M_PI/180)-M_PI/2 );

ReturnCLLocationCoordinate2DMake (lat, lon );

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.