Reputation: 6347
I need to determine offset in degrees lat/lon between two CLLocation objects. 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.
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!
Upvotes: 0
Views: 1199
Reputation: 24341
If you are using google maps sdk, you can use GMSGeometryDistance
to find the distance between 2 locations.
let distance = GMSGeometryDistance(origin, destination)
Upvotes: 3
Reputation: 3362
If I understand, what you're trying to get is the distance between 2 known location in degrees ?
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)
}
Upvotes: 1