Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save pawankmrai/ff502861fce79e5a35a2b02d2aff3af7 to your computer and use it in GitHub Desktop.

Select an option

Save pawankmrai/ff502861fce79e5a35a2b02d2aff3af7 to your computer and use it in GitHub Desktop.
Mardinate-China Map Coordinate Fix
const double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
-(CLLocationCoordinate2D)bd_encryptWithCoordinate:(CLLocationCoordinate2D)coordinate{
double x = coordinate.longitude;
double y = coordinate.latitude;
double z = sqrt (x * x + y * y) + 0.00002 * sin (y * x_pi);
double theta = atan2 (y, x) + 0.000003 * cos (x * x_pi);
double bd_lon = z * cos (theta) + 0.0065;
double bd_lat = z * sin (theta) + 0.006;
return [self bd_decryptWithCoordinate:CLLocationCoordinate2DMake(bd_lat, bd_lon)];
}
-(CLLocationCoordinate2D)bd_decryptWithCoordinate:(CLLocationCoordinate2D)coordinate{
double bd_lon = coordinate.longitude;
double bd_lat = coordinate.latitude;
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);
double gg_lon = z * cos (theta);
double gg_lat = z * sin (theta);
return CLLocationCoordinate2DMake(gg_lat, gg_lon);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment