计算两个 CLLocationCoordinate2D 位置之间的偏移量
Calculate offset between two CLLocationCoordinate2D locations
我需要确定两个 CLLocation 对象之间的偏移量 lat/lon。我见过很多关于如何根据距离和方位计算新位置的示例,但这不是我需要的。
在我的例子中,这两个位置是已知的,我要获取的是两个已知位置之间的 CLLocationDegrees 纬度和 CLLocationDegrees 经度,以便将偏移量应用于其他坐标。
class func getDistancesInDegrees(origin:CLLocationCoordinate2D, destination:CLLocationCoordinate2D) -> (degLat: CLLocationDegrees, degLon:CLLocationDegrees) {
var latidueDegrees:CLLocationDegrees = 0.0
var longitudeDegrees:CLLocationDegrees = 0.0
//...
return (degLat: latidueDegrees, degLon:longitudeDegrees)
}
有人知道如何完成此操作的好例子吗?谢谢!
据我了解,您要获取的是 2 个已知位置之间的距离(以度为单位)?
如果是这样,请尝试:
class func getDistancesInDegrees(origin:CLLocationCoordinate2D, destination:CLLocationCoordinate2D) -> (degLat: CLLocationDegrees, degLon:CLLocationDegrees) {
var latidueDegrees:CLLocationDegrees = Double(origin.coordinate.latitude) - Double(destination.coordinate.latitude)
var longitudeDegrees:CLLocationDegrees = Double(origin.coordinate.longitude) - Double(destination.coordinate.longitude)
return (degLat: latidueDegrees, degLon:longitudeDegrees)
}
如果您正在使用 google 地图 sdk,您可以使用 GMSGeometryDistance
来计算两个位置之间的距离。
let distance = GMSGeometryDistance(origin, destination)
我需要确定两个 CLLocation 对象之间的偏移量 lat/lon。我见过很多关于如何根据距离和方位计算新位置的示例,但这不是我需要的。
在我的例子中,这两个位置是已知的,我要获取的是两个已知位置之间的 CLLocationDegrees 纬度和 CLLocationDegrees 经度,以便将偏移量应用于其他坐标。
class func getDistancesInDegrees(origin:CLLocationCoordinate2D, destination:CLLocationCoordinate2D) -> (degLat: CLLocationDegrees, degLon:CLLocationDegrees) {
var latidueDegrees:CLLocationDegrees = 0.0
var longitudeDegrees:CLLocationDegrees = 0.0
//...
return (degLat: latidueDegrees, degLon:longitudeDegrees)
}
有人知道如何完成此操作的好例子吗?谢谢!
据我了解,您要获取的是 2 个已知位置之间的距离(以度为单位)?
如果是这样,请尝试:
class func getDistancesInDegrees(origin:CLLocationCoordinate2D, destination:CLLocationCoordinate2D) -> (degLat: CLLocationDegrees, degLon:CLLocationDegrees) {
var latidueDegrees:CLLocationDegrees = Double(origin.coordinate.latitude) - Double(destination.coordinate.latitude)
var longitudeDegrees:CLLocationDegrees = Double(origin.coordinate.longitude) - Double(destination.coordinate.longitude)
return (degLat: latidueDegrees, degLon:longitudeDegrees)
}
如果您正在使用 google 地图 sdk,您可以使用 GMSGeometryDistance
来计算两个位置之间的距离。
let distance = GMSGeometryDistance(origin, destination)