Hi I am trying to use geocodeAddressString to convert the address to a placemark on the map, but whatever address I passed to this method, the below block will never be executed, could anyone give me some light? Thanks a lot By the way, I can see "before" and "after" on the concole, but without "hello"
let geo = CLGeocoder()
print("before")
geo.geocodeAddressString(("4 Bradford St, Perth WA 6050"), completionHandler: {
(placemarks, error) -> Void in
print ("hello")
if let placemark = placemarks?[0]
{
self.mapView.addAnnotation(MKPlacemark(placemark: placemark))
}
})
print ("after")
Use this
import CoreLocation
let address = "1 Infinite Loop, CA, USA"
let geocoder = CLGeocoder()
geocoder.geocodeAddressString(address, completionHandler: {(placemarks, error) -> Void in
if((error) != nil){
print("Error", error)
}
if let placemark = placemarks?.first {
let coordinates:CLLocationCoordinate2D = placemark.location!.coordinate
}
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With