Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Get location from postal code in Swift 3.0

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 3.10k
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: