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

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

作者: mqhong | 来源:发表于2017-06-30 16:38 被阅读1209次

    2017年06月30日星期五


    • 今天测试美眉跑过来和我说地图模块中的定位是有问题的,有偏移量,而且偏移量比较随机。我狡辩说没问题,是手机定位不准确.... 认真看了代码之后,感觉是不是定位之后获取坐标的时候小数点没有获取够啊...
    • 未果...
    • 咨询了一下做地图的大牛,发现是因为百度地图自己的定位因为隐私还是其他原因,和其他地图的定位坐标有偏移量,SDK中还是提供了坐标转换的功能。如下,
    
        // 设备的当前位置
        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);
    }
    
    

    相关文章

      网友评论

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

          本文链接:https://www.haomeiwen.com/subject/efkicxtx.html