func getAddressFromLatLon() {
var locManager = CLLocationManager()
locManager.requestWhenInUseAuthorization()
var currentLocation = CLLocation()
if(CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedWhenInUse ||
CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorized){
currentLocation = locManager.location!
}
var center : CLLocationCoordinate2D = CLLocationCoordinate2D()
let lat: Double = Double(currentLocation.coordinate.latitude)
//21.228124
let lon: Double = Double(currentLocation.coordinate.longitude)
//72.833770
let ceo: CLGeocoder = CLGeocoder()
center.latitude = lat
center.longitude = lon
let geoCoder = CLGeocoder()
var placemark: AnyObject
var error: NSError
geoCoder.reverseGeocodeLocation(locManager.location!, completionHandler: { (placemark, error) -> Void in
if error != nil {
print("Error: \(error?.localizedDescription)")
return
}
if (placemark?.count)! > 0 {
let pm = (placemark?[0])! as CLPlacemark
//self.addressString = pm.locality! + pm.country!
let adress = pm.locality! + " " + pm.country!
print(adress)
} else {
print("Error with data")
}
})
}
Entschuldigen Sie diese grundlegende Frage. Ich bin relativ neu zu schnell und ich versuche, geocode eine geographische Breite und Länge umzukehren. Ich versuche, die Adresse von der umgekehrten Geocodierung zurückzugeben, aber es scheint zu Null zurückzukehren. Die fragliche Funktion ist getAddressFromLatLon() und ich habe versucht, einen Rückgabetyp hinzuzufügen, aber es gibt Nil zurück. Wenn ich in der Funktion selbst drucke, wird der korrekte Wert gedruckt, aber aus irgendeinem Grund habe ich Schwierigkeiten, die Adresse zurückzugeben, damit ich sie an andere Klassen/Funktionen weitergeben kann.Rückgabetyp Nill
func getAddressFromLatLon() ist eine Leere Funktion. Sie können nicht erwarten, dass es irgendeinen Wert zurückgibt. – Developer
Noch eine Sache, die ich bestätigen möchte, ist Print (Adresse) zeigt das gewünschte Ergebnis? .. – Developer
hast du lat lange in dieser Funktion? – KKRocks