[英]Calculate offset between two CLLocationCoordinate2D locations
I need to determine offset in degrees lat/lon between two CLLocation objects. 我需要确定两个CLLocation对象之间的纬度/经度偏移。 I have seen many examples of how to calculate a new location based on a distance and bearing but this is not what I need. 我已经看到了许多有关如何根据距离和方位计算新位置的示例,但这不是我所需要的。
In my case, the two locations are known and what I am trying to obtain is the CLLocationDegrees latitude and CLLocationDegrees longitude between the two known locations in order to have an offset to apply to other coordinates. 在我的情况下,这两个位置是已知的,而我试图获取的是两个已知位置之间的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)
}
Does anybody know of a good example of how to accomplish this? 有人知道如何做到这一点的好例子吗? Thanks! 谢谢!
If you are using google maps sdk, you can use GMSGeometryDistance
to find the distance between 2 locations. 如果您使用的是Google Maps SDK,则可以使用GMSGeometryDistance
查找2个位置之间的距离。
let distance = GMSGeometryDistance(origin, destination)
Refer https://developers.google.com/maps/documentation/ios-sdk/reference/group___geometry_utils.html#ga423e751bcbe4ea974049f4b78d90a86b 请参阅https://developers.google.com/maps/documentation/ios-sdk/reference/group___geometry_utils.html#ga423e751bcbe4ea974049f4b78d90a86b
If I understand, what you're trying to get is the distance between 2 known location in degrees ? 据我了解,您要获取的是2个已知位置之间的距离(以度为单位)?
If this is it then try : 如果是这样,请尝试:
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)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.