Я использую MapKit
, чтобы получить текущее местоположение, но оно не получает никакого местоположения
import UIKit
import MapKit
class NewLocationController: UIViewController,CLLocationManagerDelegate {
@IBOutlet weak var nameTextField: UITextField!
@IBOutlet weak var descriptionTextField: UITextField!
@IBOutlet weak var latitudeTextField: UITextField!
@IBOutlet weak var longtitudeTextField: UITextField!
var delegate: newLocationDelegate?
var locationManager: CLLocationManager = CLLocationManager()
var currentLocation: CLLocationCoordinate2D?
override func viewDidLoad() {
super.viewDidLoad()
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager.distanceFilter = 10
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
// Do any additional setup after loading the view.
}
func locationManager (_ manager: CLLocationManager, didUpdateLocations locations:[CLLocation]){
let loc: CLLocation = locations.last!
currentLocation = loc.coordinate
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func addNewLocation(title: String, description: String, lat: Double, long: Double){
let location : FencedAnnotation = FencedAnnotation(newTitle: title, newSubtitle: description, lat: lat, long: long)
delegate!.didSaveLocation(location)
self.navigationController?.popViewController(animated: true)
}
@IBAction func saveNewAnimal(_ sender: Any) {
addNewLocation(title: nameTextField.text!, description: descriptionTextField.text!, lat:Double(latitudeTextField.text!)!, long:Double(longtitudeTextField.text!)!)
}
@IBAction func saveCurrentLocation(_ sender: Any) {
self.latitudeTextField.text = "\(currentLocation!.latitude)"
self.longtitudeTextField.text = "\(currentLocation!.longitude)"
}