@IBAction func ValidButton(_ sender: Any) {
Task { @MainActor in
if verif() {
//do some stuff
}print("it pass throught")
}
verif() -> Bool {
bool = true
//do some stuff and make my bool false
var lat1 = 0.00
var lat2 = 0.00
var long1 = 0.00
var long2 = 0.00
Task {
do {
let coordinates = try await getLatLongFromAddress(withAddress: address1)
lat1 = coordinates.latitude
long1 = coordinates.longitude
print("when i call it : lat1 : ",lat1," long1 : ",long1)
} catch {
print(error)
}
do {
let coordinates = try await getLatLongFromAddress(withAddress: address2)
lat2 = coordinates.latitude
long2 = coordinates.longitude
print("when i call it : lat1 : ",lat1," long1 : ",long1)
} catch {
print(error)
}
}
print(" lat1 : ", lat1," long1 : ",long1)
print(" lat2 : ",lat2," long2 : ",long2)
//do some stuff
return bool
}
//myfunction
func getLatLongFromAddress(withAddress address: String) async throws -> CLLocationCoordinate2D {
let geocoder = CLGeocoder()
let placemarks = try await geocoder.geocodeAddressString(address)
let location = placemarks[0].location // for now we’ll assume [0] always exists
let result = location!.coordinate
return result // for now we’ll assume the coordinate always exists
}
here is the log :
lat1 : 0.0 long1 : 0.0
lat2 : 0.0 long2 : 0.0
2023-01-02 16:32:36.503786+0100 myApp[8758:254961] [Client] {"msg":"#NullIsland Received a latitude or longitude from getLocationForBundleID that was exactly zero", "latIsZero":0, "lonIsZero":0, "location":'80 B6 C8 08 03 00 00 00'}
end
it pass through
when i call it : lat1 : 43.5982309 long1 : 1.4313821
2023-01-02 16:32:36.554774+0100 myApp[8758:254659] [Client] {"msg":"#NullIsland Received a latitude or longitude from getLocationForBundleID that was exactly zero", "latIsZero":0, "lonIsZero":0, "location":'80 36 D1 08 03 00 00 00'}
when i call it : lat1 : 43.5982309 long1 : 1.4313821
default
Topic:
Programming Languages
SubTopic:
Swift
Tags: