CLGeocoder() async problem

Hi,

so i am using a CLGeocoder() and i got a async problem and i don't know how to repair because i in my function i need to return a bool value. but in the log we can clearly see the asynchrone in the log .

how can i fix it ? i already many many different way to get lat and long from address but all of them got the asychrone problem because is still very similar to my code .

if i put my return in mygeocoder "i got Unexpected non-void return value in void function" how can i "synchrone" my code ?

Here is my code:

//getLongFromAddress is exactely the same 
func getLatFromAddress(`let` address:String) -> Double {
    let geocoder = CLGeocoder()
    var lat = 0.00
    geocoder.geocodeAddressString(address) { placemarks, error in 
        
        let placemark = placemarks?.first
        if placemark?.location?.coordinate.latitude != nil {
            lat = (placemark?.location?.coordinate.latitude)!
        }else {
            //print(error as Any)
        }
        //Here i get my lat
        print("Lat: \(lat)")
    }
    //here my late is still 0.00
    return lat
}

Where I call my function:

func checkAddress() -> Bool {
    var check = true
    var lat1 = 0.00
    var long1 = 0.00
    var lat2 = 0.00
    var long2 = 0.00
    
    address1 = "Paris"
    address2 = "London"

    lat1 = getLatFromAddress(let: address1)
    long1 = getLongFromAddress(let: address1)
    
    lat2 = getLatFromAddress(let: address2)
    long2 = getLongFromAddress(let: address2)
    
    print(lat1," - ",long1)
    print(lat2," - ",long2)

    let coordinate₀ = CLLocation(latitude: lat1, longitude: long1)
    let coordinate₁ = CLLocation(latitude: lat2, longitude: long2)

    //get the distance to meter and with meterToKiloleter convert meter into kilometer
    let distance = meterToKilometer(let:coordinate₀.distance(from: coordinate₁))

    if distance > 50 {
        check = false
    }
    return check
}

Here is the log:

0.0  -  0.0
0.0  -  0.0
2022-12-02 18:46:06.936965+0100 Storyboard[10796:272148] [Client] {"msg":"#NullIsland Received a latitude or longitude from getLocationForBundleID that was exactly zero", "latIsZero":0, "lonIsZero":0, "location":'50 67 46 6F 01 00 00 00'}
2022-12-02 18:46:06.938224+0100 Storyboard[10796:272266] [Client] {"msg":"#NullIsland Received a latitude or longitude from getLocationForBundleID that was exactly zero", "latIsZero":0, "lonIsZero":0, "location":'50 27 4F 6F 01 00 00 00'}
2022-12-02 18:46:06.939091+0100 Storyboard[10796:272156] [Client] {"msg":"#NullIsland Received a latitude or longitude from getLocationForBundleID that was exactly zero", "latIsZero":0, "lonIsZero":0, "location":'50 E7 7A 6F 01 00 00 00'}
2022-12-02 18:46:06.939753+0100 Storyboard[10796:272501] [Client] {"msg":"#NullIsland Received a latitude or longitude from getLocationForBundleID that was exactly zero", "latIsZero":0, "lonIsZero":0, "location":'50 E7 57 6F 01 00 00 00'}
Lat: 48.8567879
Long: -0.0793965
Lat: 51.5033466
Long: 2.3510768

up

up

up

CLGeocoder() async problem
 
 
Q