Ich versuche herauszufinden, wie man den aktuellen Standort mit SWIFT für eine iOS-App in XCODE abrufen kann.Wie bekomme ich den aktuellen Standort in Swift iOS Programmierung?
Ich folgte diesem Tutorial here, aber aus irgendeinem Grund funktioniert mein Code nicht. Ich denke, das liegt daran, dass ich eine aktualisierte Xcode-Versionierung verwende. Aus irgendeinem Grund hat mein Delegierter verschiedene Parameter und ich bin mir nicht sicher, warum, aber wenn ich mein Programm erstelle, fragt es mich nicht einmal, ob ich überhaupt Standortdienste erlauben möchte.
Hier ist mein Code
override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.requestWhenInUseAuthorization();
self.locationManager.startUpdatingLocation();
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// GPS STUFF
// UPDATE LOCATION
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
CLGeocoder().reverseGeocodeLocation(manager.location!) { (placemarks, ErrorType) -> Void in
if(ErrorType != nil)
{
print("Error: " + ErrorType!.localizedDescription);
return;
}
if(placemarks?.count > 0)
{
let pm = placemarks![0] ;
self.displayLocationInfo(pm);
}
}
}
// STOP UPDATING LOCATION
func displayLocationInfo(placemark: CLPlacemark)
{
self.locationManager.stopUpdatingLocation();
print(placemark.locality);
print(placemark.postalCode);
print(placemark.administrativeArea);
print(placemark.country);
}
Auch in info.plist Ich habe auch NSLocationWhenInUseUsageDescription.
würde Ratschläge
Nein, das hat auch nicht funktioniert. –
Sieht alles so aus, als könnte es in meiner locationManager Funktion falsch liegen? –
Sie haben vergessen, mapView.showsUserLocation = true in Ihrer viewDidLoad zu füllen, lassen Sie es uns versuchen. – Khuong