Skip to content

Commit

Permalink
#22 Remove location service when accuracy is very low
Browse files Browse the repository at this point in the history
  • Loading branch information
sameerdhulap committed Jun 27, 2024
1 parent 61c53b7 commit e37bfdc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 0 additions & 1 deletion Sources/WoosmapGeofencing/Business Logic/Location.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public class Locations {
// create Location ID
let locationId = UUID().uuidString
let details = "Status \(UIApplication.shared.applicationState.rawValue), accuracy=\(location.horizontalAccuracy), Speed=\(location.speed)"
debugPrint(details)
let entry = Location(locationId: locationId, latitude: location.coordinate.latitude, longitude: location.coordinate.longitude, dateCaptured: Date(), descriptionToSave:details )
//Save in Core DB
let newRec:LocationDB = try entry.dbEntity()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ public class LocationServiceCoreImpl: NSObject,
self.startUpdatingLocation()
}
private var lastfatchLocation: CLLocation?
private var invalidLocationTimer: Timer?
/// Callback when new location receive form device
/// - Parameters:
/// - manager: location service
Expand All @@ -283,6 +284,13 @@ public class LocationServiceCoreImpl: NSObject,
return
}
if(newLocation.horizontalAccuracy > 100 || newLocation.horizontalAccuracy < -1){
if(invalidLocationTimer == nil){
invalidLocationTimer = Timer (timeInterval: 3, repeats: false, block: { Timer in
self.stopUpdatingLocation()
self.invalidLocationTimer?.invalidate()
self.invalidLocationTimer = nil
})
}
return //Less accurate data
}
//Do not consume batter if app is in background
Expand All @@ -293,6 +301,7 @@ public class LocationServiceCoreImpl: NSObject,
batteryLevel = batteryLevel == -1 ? 1.0:batteryLevel
if(batteryLevel <= 0.1 && UIDevice.current.batteryState != UIDevice.BatteryState.charging)
{
self.stopUpdatingLocation()
return //less then 10% battery remain on device ignore background processing
}
}
Expand Down

0 comments on commit e37bfdc

Please sign in to comment.