Calculate Total Traveled Distance iOS Swift

update: Xcode 8.3.2 • Swift 3.1 The problem there is because you are always getting the same location over and over again. Try like this: import UIKit import MapKit class ViewController: UIViewController, CLLocationManagerDelegate { @IBOutlet weak var mapView: MKMapView! let locationManager = CLLocationManager() var startLocation: CLLocation! var lastLocation: CLLocation! var startDate: Date! var traveledDistance: Double … Read more

Why the CLLocationManager delegate is not getting called in iPhone SDK 4.0?

I had a similar error, and is solved now. The issue is declaring locationManager variable locally. Declare it instead as a class variable and make sure it is retained either directly or via property retain (or strong if you use ARC). That solves the problem! The issue was de locationManager variable was released and never … Read more

CLLocation Category for Calculating Bearing w/ Haversine function

Your code seems fine to me. Nothing wrong with the calculous. You don’t specify how far off your results are, but you might try tweaking your radian/degrees converters to this: double DegreesToRadians(double degrees) {return degrees * M_PI / 180.0;}; double RadiansToDegrees(double radians) {return radians * 180.0/M_PI;}; If you are getting negative bearings, add 2*M_PI to … Read more

Calculating bearing between two CLLocation points in Swift [duplicate]

Here is an Objective-C solution CLLocation Category for Calculating Bearing w/ Haversine function which can easily be translated to Swift: func degreesToRadians(degrees: Double) -> Double { return degrees * .pi / 180.0 } func radiansToDegrees(radians: Double) -> Double { return radians * 180.0 / .pi } func getBearingBetweenTwoPoints1(point1 : CLLocation, point2 : CLLocation) -> Double … Read more

How to stop multiple times method calling of didUpdateLocations() in ios

While allocating your LocationManager object you can set the distanceFilter property of the LocationManager. Distance filter property is a CLLocationDistance value which can be set to notify the location manager about the distance moved in meters. You can set the distance filter as follows: LocationManager *locationManger = [[CLLocationManager alloc] init]; locationManager.delegate = self; locationManager.distanceFilter = … Read more

didFailWithError: Error Domain=kCLErrorDomain Code=0 “The operation couldn’t be completed. (kCLErrorDomain error 0.)”

If you are using the simulator: Press command + shift + , in Xcode to open the scheme editor Select the Run scheme Go to the Options tab Check ✅ Allow Location Simulation Select a Default Location in the dropdown Selecting None as your Default Location may have caused the problem.