Swift 百度地图与gcj20的相互转换

// 其他地图坐标转百度地图坐标
func gcj02_To_Bd09(longitude: CLLocationDegrees, latitude: CLLocationDegrees) -> (gg_lon: CLLocationDegrees, gg_lat: CLLocationDegrees) { let pi = 3.141592653589793 * 3000.0 / 180.0 let x = longitude let y = latitude let z = sqrt(x * x + y * y) + 0.00002 * sin(y * pi) let theta = atan2(y, x) + 0.000003 * cos(x * pi) let bd_lon = z * cos(theta) + 0.0065 let bd_lat = z * sin(theta) + 0.006 return (bd_lon, bd_lat) }
// 百度地图坐标转其他地图坐标 func bd09_To_Gcj02(bd_lon: CLLocationDegrees, bd_lat: CLLocationDegrees)
-> (gg_lon: CLLocationDegrees, gg_lat: CLLocationDegrees){ let pi = 3.141592653589793 * 3000.0 / 180.0 let x = bd_lon - 0.0065 let y = bd_lat - 0.006 let z = sqrt(x * x + y * y) - 0.00002 * sin(y * pi) let theta = atan2(y, x) - 0.000003 * cos(x * pi) let gg_lon = z * cos(theta) let gg_lat = z * sin(theta) return (gg_lon, gg_lat) }

百度地图 百度坐标 (BD-09)
腾讯地图 火星坐标(GCJ-02)
高德地图 火星坐标(GCJ-02)
谷歌地图(中国) 火星坐标(GCJ-02)
搜狐搜狗地图 搜狗坐标(GCJ-02)

posted @ 2017-06-21 15:51  乐启榜  阅读(626)  评论(0编辑  收藏  举报