react-native-geolocation-service icon indicating copy to clipboard operation
react-native-geolocation-service copied to clipboard

Store if mocked location on iOS (15+)

Open txbrown opened this issue 1 year ago • 0 comments

At the moment the mocked field is only set for Android implementation. For the app we're working on I created the following extesion and made a patch for the moment. This issue is so that we can add it officially to the package in LocationUtils.swift

func locationToDict(_ location: CLLocation) -> [String: Any] {
    return [
        "coords": [
            "latitude": location.coordinate.latitude,
            "longitude": location.coordinate.longitude,
            "altitude": location.altitude,
            "accuracy": location.horizontalAccuracy,
            "altitudeAccuracy": location.verticalAccuracy,
            "heading": location.course,
            "speed": location.speed,
            "mocked": location.isSimulated()
        ],
        "timestamp": location.timestamp.timeIntervalSince1970 * 1000 // ms
    ]
}
extension CLLocation {
    func isSimulated() -> Bool {
        if #available(iOS 15.0, *) {
            return self.sourceInformation?.isSimulatedBySoftware ?? false
        } else {
            return false
        }
    }
}

txbrown avatar Jan 03 '25 15:01 txbrown