How can I calculate the total distance traveled using CoreLocation in Swift
I have not yet found resources for how to do this in Swift for iOS 8,
How would you calculate the total distance traveled since you started tracking your location?
From what I've read so far, I need to save the location of the points, then calculate the distance between the current point and the last point, and then add this distance to the variable totalDistance
Objective-C is very unfamiliar to me, so I could not develop a quick syntax
Here is what I have developed so far, not sure if I am doing it right. Although the distanceFromLocation method returns all 0.0, so obviously something is wrong.
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) { var newLocation: CLLocation = locations[0] as CLLocation oldLocationArray.append(newLocation) var totalDistance = CLLocationDistance() var oldLocation = oldLocationArray.last var distanceTraveled = newLocation.distanceFromLocation(oldLocation) totalDistance += distanceTraveled println(distanceTraveled) }
ios xcode swift core-location cllocation
Yichenbman
source share