I have following code:
func addAnnotation(gesture: UIGestureRecognizer){
//touch point
var touchPoint = gesture.locationInView(self.UImapMK)
var location = UImapMK.convertPoint(touchPoint, toCoordinateFromView: self.UImapMK)
var cllocation = CLLocation(latitude: location.latitude, longitude: location.longitude)
var addressStr: String = "Undefined"
//GeoCoder
CLGeocoder().reverseGeocodeLocation(cllocation, completionHandler: { (placemark, error) -> Void in
if error == nil {
if placemark.count > 0{
var address = placemark[0] as! CLPlacemark
addressStr = "\(address.locality), \(address.administrativeArea)"
}
}
else{
addressStr = "Error"
}
println("RUN: CLgeocoder")
})
//Annotation
var annotation = MKPointAnnotation()
annotation.coordinate = location
annotation.title = addressStr
UImapMK.addAnnotation(annotation)
}
However reverseGeocodeLocation function seems to run after addAnnotation, so every time I have addressStr as "undefined".
Is there a way to make reverseGeocodeLocation run first? Thanks!