Skip to content

Commit fbbf9b1

Browse files
author
Achyut Kumar M
committed
set distanceFilter to 150 to call didUpdateLocations after user moves 150 mts
1 parent 2a753d9 commit fbbf9b1

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

GoInfoGame/GoInfoGame/LocationManagerDelegate.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ class LocationManagerDelegate: NSObject, ObservableObject, CLLocationManagerDele
1313
var locationManager = CLLocationManager()
1414
@Published var location: CLLocation?
1515
var locationUpdateHandler: ((CLLocationCoordinate2D) -> Void)?
16-
17-
var hasUpdatedLocation = false
18-
16+
1917
override init() {
2018
super.init()
2119
locationManager.delegate = self
@@ -36,13 +34,15 @@ class LocationManagerDelegate: NSObject, ObservableObject, CLLocationManagerDele
3634

3735
DispatchQueue.main.async {
3836
self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
37+
self.locationManager.distanceFilter = 150
3938
self.locationManager.startUpdatingLocation()
4039
}
4140
}
4241
}
4342

4443

4544
func stopUpdatingLocation() {
45+
print("App is pushed to background. So stopping location updates")
4646
locationManager.stopUpdatingLocation()
4747
}
4848

@@ -61,10 +61,11 @@ class LocationManagerDelegate: NSObject, ObservableObject, CLLocationManagerDele
6161

6262
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
6363
guard let mostRecentLocation = locations.last else { return }
64-
guard !hasUpdatedLocation else { return }
6564
location = mostRecentLocation
6665
locationUpdateHandler?(mostRecentLocation.coordinate)
67-
hasUpdatedLocation = true
68-
stopUpdatingLocation()
66+
}
67+
68+
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
69+
print("Error with location manager is ----\(error.localizedDescription)")
6970
}
7071
}

0 commit comments

Comments
 (0)