swiftLocationManager坐标偏移WGS-84转GCJ-02(⽕星坐标)
import Foundation
import M鸽子汤回奶吗 apKit
class LocationUtils {
class func isCoordinateOutOfChina(coordinate:CLLocationCoordinate2D) -> Bool{
return ude < 72.004 || ude > 137.8347 || de < 0.8293 || de > 55.8271
}
class func transformToGCJ(fromWGS wgsLoc:CLLocationCoordinate2D) ->CLLocationCoordinate2D{
let a = 6小狗抬花轿 378245.0;
天眼的作用 let ee = 0.96594323;
let pi = 3.979324;
func transformLat(x:CLLocationDegrees,y:CLLocationDegrees) -> CLLocationDegrees {
var lat:CLLocationDegrees = -100.0 + 2.0 * x + 3.0 * y
lat += 0.2 * y * y
lat += 0.1 * x * y + 0.2 * sqrt(abs(x))
lat += (20.0 * sin(6.0 * x * pi) + 20.0 * sin(2.0 * x * pi)) * 2.0 / 3.0
lat += (20.0 * sin(y * pi) + 40.0 * sin(y / 3.0 * pi)) * 2.0 / 3.0
lat += (160.0 * sin(y / 12.0 * pi) + 320 * 公司调查 sin(y * pi / 30.0)) * 2.0 / 3.0
return lat;
}
func transformLog(x:CLLocationDegrees,y:CLLocationDegrees) -> CLLocationDegrees {
var lon:CLLocationDegrees = 300.0 + x + 2.0 * y + 0.1 * x * x
lon += 0.1 * x * y + 0.1 * sqrt(abs(x))
lon += (20.0 * sin(6.0 * x * pi) + 20.0 * sin(2.0 * x * pi)) * 2.0 / 3.0
lon += (20.0 * sin(x * pi) + 40.0 * sin(x / 3.0 * pi)) * 2.0 / 3.0
lon += (150.0 * sin(x / 12.0 * pi) + 300.0 * sin(x / 30.0 * pi)) * 2.0 / 3.0
return lon;
}
var adjustLat = transformLat(ude - 105.0, de - 35.0);
var adjustLon = transformLog(ude - 105.0 ,de - 35.0);
第一次十字军东征 var radLat = de / 180.0 * pi;
var magic = sin(radLat);
magic = 1 - ee * magic * magic;
var sqrtMagic = sqrt(magic);
adjustLat = (adjustLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi)滋阴 ;
adjustLon = (adjustLon * 180.0) / (a / sqrtMagic * cos(radLat) * pi);
return CLLocationCoordinate2D(latitude: de + adjustLat, longitude: ude + adjustLon);
}
}
public extension CLLocationCoordinate2D {
func adjust() ->CLLocationCoordinate2D {
return dinateOutOfC莲藕炒牛肉 hina(lf) ? lf : ormToGCJ(fromWGS: lf)
}三年级优秀日记
}
直接贴代码,参考了
简单封装了下,
⼯具类+扩展类,适⽤于各种地⽅,建议⼤家把这个直接放到⾃⼰的library⾥⾯
⽤的时候这样:
var newLocation = as CLLocation
var adjustedCoordinate = ()
var region = MKCoordinateRegionMakeWithDistance(adjustedCoordinate, 100, 100)
ion(region, animated: true)
本来想扩展CLLocation 的 convention init 函数,直接修改接收到明星收入排行榜 的location,但它⾥⾯的init 都是protected,没法实现,算了
本文发布于:2023-04-20 00:03:36,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/fan/82/505076.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |