|
@@ -20,11 +20,27 @@ class ViewController: UIViewController {
|
|
|
locationManager = CLLocationManager()
|
|
|
locationManager?.delegate = self
|
|
|
locationManager?.requestAlwaysAuthorization()
|
|
|
+ locationManager?.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
|
|
|
+ locationManager?.activityType = CLActivityType.otherNavigation
|
|
|
+ locationManager?.distanceFilter = 100.0
|
|
|
}
|
|
|
|
|
|
@IBAction func buttonClicked(_ sender: Any) {
|
|
|
print("Clicked !")
|
|
|
- locationManager?.requestLocation()
|
|
|
+ //locationManager?.requestLocation()
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @IBAction func trackingEnabledChanged(_ sender: UISwitch) {
|
|
|
+ print("Switch Changed !")
|
|
|
+ switch sender.isOn {
|
|
|
+ case true:
|
|
|
+ print("ON")
|
|
|
+ locationManager?.startUpdatingLocation()
|
|
|
+ default:
|
|
|
+ print("OFF")
|
|
|
+ locationManager?.stopUpdatingLocation()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@IBOutlet weak var clickButton: UIButton!
|
|
@@ -55,15 +71,23 @@ extension ViewController: CLLocationManagerDelegate {
|
|
|
print("LocationManager didUpdateLocations: numberOfLocation: \(locations.count)")
|
|
|
let dateFormatter = DateFormatter()
|
|
|
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
|
|
|
+
|
|
|
+ placeOrder(didUpdateLocations: locations)
|
|
|
|
|
|
locations.forEach { (location) in
|
|
|
print("LocationManager didUpdateLocations: \(dateFormatter.string(from: location.timestamp)); \(location.coordinate.latitude), \(location.coordinate.longitude)")
|
|
|
- print("LocationManager altitude: \(location.altitude)")
|
|
|
print("LocationManager horizontalAccuracy: \(location.horizontalAccuracy)")
|
|
|
print("LocationManager verticalAccuracy: \(location.verticalAccuracy)")
|
|
|
- print("LocationManager speed: \(location.speed)")
|
|
|
- print("LocationManager timestamp: \(location.timestamp)")
|
|
|
- print("LocationManager course: \(location.course)")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
|
|
|
+ print("LocationManager didFailWithError \(error.localizedDescription)")
|
|
|
+ if let error = error as? CLError, error.code == .denied {
|
|
|
+ // Location updates are not authorized.
|
|
|
+ // To prevent forever looping of `didFailWithError` callback
|
|
|
+ locationManager?.stopMonitoringSignificantLocationChanges()
|
|
|
+ return
|
|
|
}
|
|
|
}
|
|
|
}
|