Ich versuche zu animieren, wo der Benutzer ist, wenn er die Standortverfolgung akzeptiert. Der Code funktioniert, wenn er bereits die Standortverfolgung akzeptiert hat und lädt dann die Ansicht, aber ich möchte die Ansicht neu laden lassen, wenn Sie auf Standortverfolgung bestätigen klicken.Standort aktualisieren, wenn der Benutzer die Standortverfolgung zulässt
override func viewDidLoad() {
super.viewDidLoad()
//Prepare to get User
if CLLocationManager.authorizationStatus() != .authorizedAlways {
// May need to change to support location based notifications
locationManager.requestAlwaysAuthorization()
print("hello")
mapView.setVisibleMapRect(mapView.visibleMapRect, animated: true)
}else {
locationManager.startUpdatingLocation()
}
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
mapView.delegate = self
}
Animation zu Benutzerstandort-Code
//Get user location
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
//Show the map at the users current location
let location = locations[0]
let span:MKCoordinateSpan = MKCoordinateSpanMake(0.02,0.02)
let myLocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude)
let region:MKCoordinateRegion = MKCoordinateRegionMake(myLocation, span)
mapView.setRegion(region, animated: true)
self.mapView.showsUserLocation = true
locationManager.stopUpdatingLocation()
}
Hey ich habe den Code hinzugefügt, aber die Funktion scheint nicht aufgerufen zu werden. –
Ah, Entschuldigung! Ich habe den Beitrag bearbeitet. Dies ist für alte schnelle. Es sollte Func locationManager sein (_ Manager: CLLocationManager, didChangeAuthorization Status: CLAuthorizationStatus) {} –
Vielen Dank! Es funktioniert jetzt, aber kann ich es zum aktuellen Standort animieren? –