将百度坐标转化为高德坐标的2种方案

方案1(民间开源版)

+ (CLLocation *)AMapLocationFromBaiduLocation:(CLLocation *)BaiduLocation;
{
    const double x_pi = M_PI * 3000.0 / 180.0;
    double x = BaiduLocation.coordinate.longitude - 0.0065, y = BaiduLocation.coordinate.latitude - 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 AMapLongitude = z * cos(theta);
    double AMapLatitude = z * sin(theta);
    CLLocation *AMapLocation = [[CLLocation alloc] initWithLatitude:AMapLatitude longitude:AMapLongitude];
    return AMapLocation;
}

方案2(高德官方版)

用法比较简单,大致格式为
http://restapi.amap.com/v3/assistant/coordinate/convert?locations=longitude,latitude&coordsys=baidu&key=AMapWebAPIKey

2 个赞