-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
48 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// LocationManager.swift | ||
// Whidy-iOS | ||
// | ||
// Created by JinwooLee on 1/29/25. | ||
// | ||
|
||
import Foundation | ||
import CoreLocation | ||
|
||
final class LocationManager: NSObject, CLLocationManagerDelegate { | ||
static let shared = LocationManager() | ||
private let locationManager = CLLocationManager() | ||
private(set) var altitude: Double? | ||
private(set) var latitude: Double? | ||
private(set) var longitude: Double? | ||
|
||
override private init() { | ||
super.init() | ||
locationManager.delegate = self | ||
locationManager.desiredAccuracy = kCLLocationAccuracyBest | ||
locationManager.requestWhenInUseAuthorization() | ||
locationManager.startUpdatingLocation() | ||
} | ||
|
||
func getManager() -> CLLocationManager { | ||
return locationManager | ||
} | ||
|
||
// CLLocationManagerDelegate 메서드 | ||
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { | ||
guard let location = locations.last else { return } | ||
latitude = location.coordinate.latitude | ||
longitude = location.coordinate.longitude | ||
altitude = location.altitude | ||
} | ||
|
||
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { | ||
Logger.error("Failed to find user's location: \(error.localizedDescription)") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters