Just a quick question on Core Location, I\'m trying to calculate the distance between two points, code is below:
-(void)locationChange:(CLLocation *)newL
In Swift
Let's create a method function that calculates distance between two locations:
func distanceBetweenTwoLocations(source:CLLocation,destination:CLLocation) -> Double{
var distanceMeters = source.distanceFromLocation(destination)
var distanceKM = distanceMeters / 1000
let roundedTwoDigit = distanceKM.roundedTwoDigit
return roundedTwoDigit
}
If you want only two digits:
extension Double{
var roundedTwoDigit:Double{
return Double(round(100*self)/100)
}
}