I want to determine if I am within a 10m radius of an area on my iphone's location information, but when I wait for the result and then go to the next process, the result of the inside/outside determination does not come back. Please tell me if I am doing something wrong.
func SpotArea_judgment(place: String, rad: Int, location:CLLocationCoordinate2D) -> Bool? {
var result: Bool?
let semaphore = DispatchSemaphore(value: 0)
let geocoder = CLGeocoder()
geocoder.geocodeAddressString(place) { (placemarks, error) in
let center = CLLocationCoordinate2D(
latitude: Double(placemarks?.first?.location?.coordinate.latitude ?? 0),
longitude: Double(placemarks?.first?.location?.coordinate.longitude ?? 0)
)
let radius: CLLocationDistance = Double(rad)
let circularRegion = CLCircularRegion(center: center, radius: radius, identifier: "identifier")
result = circularRegion.contains(location)
semaphore.signal()
}
semaphore.wait()
return result
}