swift --- GCJ-02(火星坐标)、WGS-84、BD-09坐标系转换
swift版git地址
https://github.com/JackZhouCn/JZLocationConverter-Swift
oc版地址
https://github.com/JackZhouCn/JZLocationConverter
WGS-84世界标准坐标、GCJ-02中国国测局(火星坐标)、BD-09百度坐标系转换
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)



浙公网安备 33010602011771号