Latest 1.0.1
Homepage https://github.com/JackZhouCn/JZLocationConverter-Swift
License MIT
Platforms ios 8.0

WGS-84世界标准坐标、GCJ-02中国国测局(火星坐标)、BD-09百度坐标系转换

iOS
Swift
Xcode
Carthage compatible
CocoaPods

Demo

使用

支持 Carthage,添加以下代码到你的Cartfile文件中:

github "JackZhouCn/JZLocationConverter-Swift"

支持 CocoaPods,添加以下代码到你的Podfile文件中:

pod 'JZLocationConverterSwift'

1、在APP启动时加载大陆边境线数据

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        JZLocationConverter.start(filePath: Bundle(for:JZAreaManager.self).path(forResource: "GCJ02", ofType: "json")) { (error:JZFileError?) in
            if error != nil {
                print("失败")
            }else {
                print("成功")
            }
        }
        return true
    }

2、转换方法都在转换工具单例类内

    JZLocationConverter.default

3、目前有:

WGS-84 -> GCJ-02

此接口当输入坐标为中国大陆以外时,仍旧返回WGS-84坐标

    public func wgs84ToGcj02(_ wgs84Point:CLLocationCoordinate2D,result:@escaping (_ gcj02Point:CLLocationCoordinate2D) -> Void)

GCJ-02 -> WGS-84

此接口有1-2米左右的误差,需要精确的场景慎用

    public func gcj02ToWgs84(_ gcj02Point:CLLocationCoordinate2D,result:@escaping (_ wgs84Point:CLLocationCoordinate2D) -> Void)

WGS-84 -> BD-09

    public func wgs84ToBd09(_ wgs84Point:CLLocationCoordinate2D,result:@escaping (_ bd09Point:CLLocationCoordinate2D) -> Void)

BD-09 -> WGS-84

    public func bd09ToWgs84(_ bd09Point:CLLocationCoordinate2D,result:@escaping (_ wgs84Point:CLLocationCoordinate2D) -> Void) 

GCJ-02 -> BD-09

    public func gcj02ToBd09(_ gcj02Point:CLLocationCoordinate2D,result:@escaping (_ bd09Point:CLLocationCoordinate2D) -> Void)

BD-09 -> GCJ-02

此接口有1-2米左右的误差,需要精确的场景慎用

    public func bd09ToGcj02(_ bd09Point:CLLocationCoordinate2D,result:@escaping (_ gcj02Point:CLLocationCoordinate2D) -> Void)

关于大陆边境线数据

1、默认的边境线数据位于项目的GCJ02.json文件中

2、默认的边境线数据来自「百度地图」API并转换到GCJ02

3、如果你需要使用自己的边境线数据(需要GCJ02坐标),只需要在启动时加载自己的数据即可

4、默认的大陆边境线数据范围

Latest podspec

{
    "name": "JZLocationConverterSwift",
    "version": "1.0.1",
    "summary": "WGS-84u4e16u754cu6807u51c6u5750u6807u3001GCJ-02u4e2du56fdu56fdu6d4bu5c40(u706bu661fu5750u6807)u3001BD-09u767eu5ea6u5750u6807u7cfbu8f6cu6362",
    "homepage": "https://github.com/JackZhouCn/JZLocationConverter-Swift",
    "license": "MIT",
    "authors": "JackZhouCn",
    "social_media_url": "https://twitter.com/JackZhou__",
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/JackZhouCn/JZLocationConverter-Swift.git",
        "tag": "1.0.1"
    },
    "source_files": "JZLocationConverterDemo/JZLocationConverter/**/*.swift",
    "resources": "JZLocationConverterDemo/JZLocationConverter/GCJ02.json",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This