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")
いいえ。だから、私が最後の4行のすべての行を印刷しようとすると、毎回 "0"と出てきます。 2つのジオコーディングライン(self.forwardGeocoding
)&(self.forwardGeocodingDesired
)は問題ではありませんが、正常に動作しますが、正しいDouble値が表示されない理由はわかりません。どんな提案も大変ありがとうございます。ありがとうございます。swift関数の戻り値が正しく返されない
彼らは非同期に実行します。あなたが気にしないなら、どうすればこの問題を解決できますか? –