iOS定位与实际定位偏差

1、项目中需要精确定位,用到的系统定位有偏差,查了查资料做了总结,有不足之处希望路过大神改正,虚心求教

iOS定位与实际定位偏差原因:

原来国内地图使用的坐标系统是GCJ-02(火星坐标)而iOS sdk中所用到的是国际标准的坐标系统WGS-84。我们需要把国际标准的坐标系统WGS-84坐标系统转为GCJ-02(火星坐标)就OK了


iOS定位与实际定位偏差_第1张图片

参考了许多资料,废话不多说具体实现:

1、使用 CocoaPods;pod 'JZLocationConverter'

2、在使用的地方导入头文件  #import "JZLocationConverter.h";记得使用地图协议CLLocationManagerDelegate

3、在- (void)locationManager:(CLLocationManager*)manager didUpdateLocations:(NSArray *)locations {

       CLLocation *loc = [locations firstObject];

            //维度:loc.coordinate.latitude

            //经度:loc.coordinate.longitude

            NSLog(@"转化前坐标1--------%f2========%f",loc.coordinate.latitude,loc.coordinate.longitude);

            CLLocationCoordinate2D gcj02 =            CLLocationCoordinate2DMake(loc.coordinate.latitude,loc.coordinate.longitude);

            //国际标准的坐标系统WGS-84坐标系统转为GCJ-02(火星坐标)

            CLLocationCoordinate2D bd09 = [JZLocationConverter wgs84ToGcj02:gcj02];

            NSLog(@"转化后坐标3--------%f,4========%f", bd09.latitude, bd09.longitude);

}

参考链接:IOS LocationManager定位国内偏移,火星坐标(GCJ-02)解决方法 - CSDN博客

GitHub:https://github.com/JackZhouCn/JZLocationConverter#此接口有1-2米左右的误差需要精确的场景慎用-1

iOS地图上WGS84、GCJ-02、BD-09互转解决方案 - 推酷

你可能感兴趣的:(iOS定位与实际定位偏差)