How to speed up obtaining coordinates from GPS in Swift?

I am starting and I am creating an application that receives the coordinate of the user. I am making the locationManager class below

import UIKit
import CoreLocation


class LocationManager: NSObject {
    let manager = CLLocationManager()
    var didGetLocation: ((Coordinate?) -> Void)?

    override init() {
        super.init()

        manager.delegate = self
        manager.desiredAccuracy = kCLLocationAccuracyBest
        manager.requestLocation()
    }

    func getPermission() {
        // to ask permission to the user by showing an alert (the alert message is available on info.plist)
        if CLLocationManager.authorizationStatus() == .notDetermined {
            manager.requestWhenInUseAuthorization()
        }

    }
}




extension LocationManager : CLLocationManagerDelegate {

    func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
        if status == .authorizedWhenInUse {
            manager.requestLocation()
        }
    }

    func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
        print(error.localizedDescription)
    }

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        guard let location = locations.first else {
            didGetLocation?(nil)
            return

        }
        let coordinate = Coordinate(location: location)
        if let didGetLocation = didGetLocation {
            didGetLocation(coordinate)

        }
    }
}

private extension Coordinate {
    init(location: CLLocation) {
        latitude = location.coordinate.latitude
        longitude = location.coordinate.longitude
    }
}

I simply call the property didGetLocationto get the coordinate location of the user. the code above can actually get the coordinate data. but I think it takes too much time (I got the coordinate in 5-7 seconds).

Honestly, I'm new to iOS development, is it normal to get the coordinates about 5-7 seconds? can i improve this one?

I suspect that the desired accuracy I used is - kCLLocationAccuracyBestbut if I turn on kCLLocationAccuracyHundredMeters, it seems the same

So can I improve this one? Because, if I compare with android, then it’s very fast to get the coordinate location

+6
1

: , kCLLocationAccuracyThreeKilometers, , CLLocationManager , ,

Apple Docs

var desiredAccuracy: CLLocationAccuracy { get set }

; , .

, . , , kCLLocationAccuracyKilometer, kCLLocationAccuracyBestForNavigation. .

, . . , , , , , .

iOS macOS kCLLocationAccuracyBest. watchOS kCLLocationAccuracyHundredMeters.

.

+1

All Articles