mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
48 lines
1.5 KiB
Swift
48 lines
1.5 KiB
Swift
//
|
|
// LocationHelper.swift
|
|
// RChat
|
|
//
|
|
// Created by Andrew Morgan on 24/11/2020.
|
|
//
|
|
|
|
import CoreLocation
|
|
|
|
struct MyAnnotationItem: Identifiable {
|
|
var coordinate: CLLocationCoordinate2D
|
|
let id = UUID()
|
|
}
|
|
|
|
class LocationHelper: NSObject, ObservableObject {
|
|
|
|
static let shared = LocationHelper()
|
|
static let DefaultLocation = CLLocationCoordinate2D(latitude: 51.506520923981554, longitude: -0.10689139236939127)
|
|
|
|
static var currentLocation: CLLocationCoordinate2D {
|
|
guard let location = shared.locationManager.location else {
|
|
return DefaultLocation
|
|
}
|
|
return location.coordinate
|
|
}
|
|
|
|
private let locationManager = CLLocationManager()
|
|
|
|
private override init() {
|
|
super.init()
|
|
locationManager.delegate = self
|
|
locationManager.desiredAccuracy = kCLLocationAccuracyBest
|
|
locationManager.requestWhenInUseAuthorization()
|
|
locationManager.startUpdatingLocation()
|
|
}
|
|
}
|
|
|
|
extension LocationHelper: CLLocationManagerDelegate {
|
|
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { }
|
|
|
|
public func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
|
|
print("Location manager failed with error: \(error.localizedDescription)")
|
|
}
|
|
|
|
public func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
|
|
print("Location manager changed the status: \(status)")
|
|
}
|
|
}
|