forked from BiGZ31/GpsSpooferIosApp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LocationManager.swift
37 lines (32 loc) · 1.23 KB
/
LocationManager.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import CoreLocation
import Combine
class LocationSimulator: NSObject, ObservableObject, CLLocationManagerDelegate {
private let locationManager = CLLocationManager()
@Published var currentLocation: CLLocation? = nil
override init() {
super.init()
locationManager.delegate = self
}
func startSimulatingLocation(latitude: Double, longitude: Double, altitude: Double) {
// Create a CLLocation with the correct initializer
currentLocation = CLLocation(
coordinate: CLLocationCoordinate2D(latitude: latitude, longitude: longitude),
altitude: altitude,
horizontalAccuracy: 0,
verticalAccuracy: 0,
timestamp: Date()
)
// Notify CLLocationManager to simulate location updates
locationManager.startUpdatingLocation()
}
func stopSimulatingLocation() {
locationManager.stopUpdatingLocation()
}
// CLLocationManagerDelegate method
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let newLocation = currentLocation {
// Use the simulated location instead of the real location
currentLocation = newLocation
}
}
}