For proper navigation, you first need to set up your location manager object like this
fileprivate func initLocationManager() { locationManager = CLLocationManager(); locationManager!.delegate = self; locationManager!.desiredAccuracy = kCLLocationAccuracyBest; locationManager!.activityType = .automotiveNavigation; if LocationTracker.authorized() == false { requestAuthorization() } }
After that, you need to find a legal location, because in the ios system try to give a better place, but you are not sure if some temporary location also comes from the cache or your location may be zick zack, so you need the following code in locationUpdate
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { if locations.count > 0 { let _ = locations.first let location = locations[locations.count-1] let maxAge:TimeInterval = 60; let requiredAccuracy:CLLocationAccuracy = 100; let locationIsValid:Bool = Date().timeIntervalSince(location.timestamp) < maxAge && location.horizontalAccuracy <= requiredAccuracy; if locationIsValid { NSLog(",,, location : %@",location); NSLog("valid locations....."); } } }
your navigation is going smoothly, but note that location accuracy is not very good on the iPad. This type of module only works for iphone.
source share