From 7d96ef1a11f40dcd25be1482d2be8fa9c070be8c Mon Sep 17 00:00:00 2001 From: Daniele Margutti Date: Thu, 24 Dec 2020 10:15:38 +0100 Subject: [PATCH] fix #318 lastLocation has not set correctly on first pass --- .../Request/Requests/GPSLocation/GPSLocationRequest.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sources/SwiftLocation/Request/Requests/GPSLocation/GPSLocationRequest.swift b/Sources/SwiftLocation/Request/Requests/GPSLocation/GPSLocationRequest.swift index 11a8c750..dd26f42c 100644 --- a/Sources/SwiftLocation/Request/Requests/GPSLocation/GPSLocationRequest.swift +++ b/Sources/SwiftLocation/Request/Requests/GPSLocation/GPSLocationRequest.swift @@ -141,6 +141,8 @@ public class GPSLocationRequest: RequestProtocol, Codable { } if let previousLocation = lastLocation { + // in case we have already received a first valid location and we need to validate + // minDistance or minInterval we want to do these checks here. if options.minDistance > kCLDistanceFilterNone, previousLocation.distance(from: data) > options.minDistance { return .notMinDistance // minimum distance since last location is not respected. @@ -150,6 +152,12 @@ public class GPSLocationRequest: RequestProtocol, Codable { previousLocation.timestamp.timeIntervalSince(Date()) >= minInterval { return .notMinInterval // minimum time interval since last location is not respected. } + } else { + // This is the first time we receive a location inside this request. + // We have validated the accuracy so we can store it. Subsequent + // call of the validateData method will land in the if above and also + // check the minDistance and minInterval. + lastLocation = data } return nil