/// 百度转高德
static CLLocationCoordinate2D BDTOGD(CLLocationCoordinate2D coordinate) {
double pi = M_PI * 3000.0 / 180.0;
double x = coordinate.longitude - 0.0065;
double y = coordinate.latitude - 0.006;
double z = sqrt(x * x + y * y) - 0.00002 * sin(y * pi);
double theta = atan2(y, x) - 0.000003 * cos(x * pi);
return CLLocationCoordinate2DMake(z * sin(theta), z * cos(theta));
}
/// 高德转百度
static CLLocationCoordinate2D GDTOBD(CLLocationCoordinate2D coordinate) {
double pi = M_PI * 3000.0 / 180.0;
double lng = coordinate.longitude;
double lat = coordinate.latitude;
double z = sqrt(lng * lng + lat * lat) + 0.00002 * sin(lat * pi);
double theta = atan2(lat, lng) + 0.000003 * cos(lng * pi);
return CLLocationCoordinate2DMake(z * sin(theta) + 0.006, z * cos(theta) + 0.0065);
}
网友评论