1. import coreLocation in your controller.
import CoreLocation
2. Add this function to your view controller.
func getLocationFromPostalCode(postalCode : String){
let geocoder = CLGeocoder()
geocoder.geocodeAddressString(postalCode) {
(placemarks, error) -> Void in
// Placemarks is an optional array of type CLPlacemarks, first item in array is best guess of Address
if let placemark = placemarks?[0] {
if placemark.postalCode == postalCode{
// you can get all the details of place here
print("\(placemark.locality)")
print("\(placemark.country)")
}
else{
print("Please enter valid zipcode")
}
}
}
}
0 Comment(s)