百度与高德腾讯等火星坐标系之间的经纬度转换

2023-11-08  本文已影响0人  _moses
/// 百度转高德
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);
}
上一篇 下一篇

猜你喜欢

热点阅读