func getLatsAndLongs() -> (LATITUDE: Double, LONGITUDE: Double, DESIREDLAT: Double, DESIREDLONG: Double) {
self.forwardGeocoding("\(addressTxtFld.text) \(cityTxtFld.text), \(stateTxtFld.text)", completion: {
success, coordinate in
if success {
self.lat = coordinate.latitude
self.long = coordinate.longitude
print("\(self.lat) is the latitude for the initial location")
print("\(self.long) is the longitude for the initial location")
self.INITIAL_DESTINATION_LATITUDE = self.lat
self.INITIAL_DESTINATION_LONGITUDE = self.long
var initialLocation = CLLocationCoordinate2DMake(self.INITIAL_DESTINATION_LATITUDE, self.INITIAL_DESTINATION_LONGITUDE)
} else {
print("Error at forwardGeocoding @willcohen @ERRORALERT")
}
})
self.forwardGeocodingDesired("\(addressTxtFldDest.text) \(cityTxtFldDest.text), \(stateTxtFldDest.text)", completion: {
success, coordinate in
if success {
self.desiredLat = coordinate.latitude
self.desiredLong = coordinate.longitude
print("\(self.desiredLat) is the latitude for the desired location")
print("\(self.desiredLong) is the longitude for the desired locaiton")
self.DESIRED_DESTIANTION_LATITUDE = self.desiredLat
self.DESIRED_DESTINATION_LONGITUDE = self.desiredLong
var desiredLocation = CLLocationCoordinate2DMake(self.DESIRED_DESTIANTION_LATITUDE, self.DESIRED_DESTINATION_LONGITUDE)
} else {
print("Error at forwardGeocodingDesired @willcohen @ERRORALERT")
}
})
return (lat,long,desiredLat,desiredLong)
}
let latsAndLongs = getLatsAndLongs()
let latFF = latsAndLongs.LATITUDE
let longFF = latsAndLongs.LONGITUDE
let latDFF = latsAndLongs.DESIREDLAT
let longDFF = latsAndLongs.DESIREDLONG
print("\(latFF) final lat")
print("\(longFF) final long")
print("\(latDFF) final latD")
print("\(longDFF) final longD")
Okay. Wenn ich also versuche, alle Zeilen der letzten 4 Zeilen zu drucken, wird jedes Mal "0" ausgegeben. Beachten Sie, dass die beiden Geocodierungszeilen (self.forwardGeocoding
) & (self.forwardGeocodingDesired
) nicht die Probleme sind, sie funktionieren gut, aber ich habe keine Ahnung, warum sie nicht die richtigen Double-Werte drucken. Irgendwelche Vorschläge würden sehr geschätzt werden, danke.swift Funktion Rückgabewerte werden nicht korrekt zurückgegeben
sie asynchron tun auszuführen. Wenn es Ihnen nichts ausmacht, wie würde ich das beheben? –