获取当前位置邮政编码ios swift

时间:2015-09-22 20:12:58

标签: ios swift ios9

如何使用位置服务获取用户所在的当前邮政编码?

2 个答案:

答案 0 :(得分:2)

    //finding address given the coordinates
    CLGeocoder().reverseGeocodeLocation(location, completionHandler: {(placemarks, error) -> Void in

        if error != nil {
            print("Reverse geocoder failed with error" + error!.localizedDescription)
            return
        }

        if placemarks!.count > 0 {
            let pm = placemarks![0]

            print(pm.postalCode) //prints zip code
        }
        else {
           print("Problem with the data received from geocoder")
        }
    })

答案 1 :(得分:0)

使用CLGeocoder类的reverseGeocodeLocation(_:completionHandler:)方法。