IOS 使用自带的GPS获取坐标位置在百度地图上定位有偏移问题

2017-06-30  本文已影响1209人  mqhong

2017年06月30日星期五



    // 设备的当前位置
    CLLocation *currLocation = [locations lastObject];
    CLLocationCoordinate2D test = CLLocationCoordinate2DMake(currLocation.coordinate.latitude, currLocation.coordinate.longitude);
    
    //获取百度地图base64加密的自己的坐标
    NSDictionary *testdic = BMKConvertBaiduCoorFrom(test,BMK_COORDTYPE_GPS);
    //解base64的加密
    CLLocationCoordinate2D realBadiDuPoint = BMKCoorDictionaryDecode(testdic);


另,附百度地图坐标系和IOS原生地图(高德)的坐标系的转换

百度地图坐标与苹果自带地图经纬度之间的相互转换方法:

/// 百度坐标转高德坐标
+ (CLLocationCoordinate2D)GCJ02FromBD09:(CLLocationCoordinate2D)coor
{
    CLLocationDegrees x_pi = 3.14159265358979324 * 3000.0 / 180.0;
    CLLocationDegrees x = coor.longitude - 0.0065, y = coor.latitude - 0.006;
    CLLocationDegrees z = sqrt(x * x + y * y) - 0.00002 * sin(y * x_pi);
    CLLocationDegrees theta = atan2(y, x) - 0.000003 * cos(x * x_pi);
    CLLocationDegrees gg_lon = z * cos(theta);
    CLLocationDegrees gg_lat = z * sin(theta);
    return CLLocationCoordinate2DMake(gg_lat, gg_lon);
}

// 高德坐标转百度坐标
+ (CLLocationCoordinate2D)BD09FromGCJ02:(CLLocationCoordinate2D)coor
{
    CLLocationDegrees x_pi = 3.14159265358979324 * 3000.0 / 180.0;
    CLLocationDegrees x = coor.longitude, y = coor.latitude;
    CLLocationDegrees z = sqrt(x * x + y * y) + 0.00002 * sin(y * x_pi);
    CLLocationDegrees theta = atan2(y, x) + 0.000003 * cos(x * x_pi);
    CLLocationDegrees bd_lon = z * cos(theta) + 0.0065;
    CLLocationDegrees bd_lat = z * sin(theta) + 0.006;
    return CLLocationCoordinate2DMake(bd_lat, bd_lon);
}

上一篇 下一篇

猜你喜欢

热点阅读