location 정보
사용 방법
findAddressWithType(type:.Street, lat: lat, lon: lon) { (str) in
self?.myLocationLabel.text = str // "현위치 : " + str
}
소스
public enum AddressType:String {
case Name = "Name" //04309 대한민국 서울특별시 용산구 청파동2가 71-19
case ZipCode = "ZIP" //04309
case Country = "Country" //대한민국
case State = "State" //서울특별시
case City = "City" //용산구
case Street = "Street" //청파동2가 71-19
case Thoroughfare = "Thoroughfare" //청파동2가
case SubThoroughfare = "SubThoroughfare" //71-19
case CountryCode = "CountryCode" //KR
}
func findAddressWithType(type:AddressType, lat:Double, lon:Double, completion:((_ address:String)->Void)?) {
if(self.findAddressBlock == nil){
self.findAddressBlock = completion
}
let location = CLLocation(latitude: lat, longitude: lon)
CLGeocoder().reverseGeocodeLocation(location, completionHandler: { (placemarks, error) -> Void in
// Place details
var placeMark: CLPlacemark!
placeMark = placemarks?[0]
if((self.findAddressBlock) != nil){
if let ret = placeMark?.addressDictionary![type.rawValue] as? String {
self.findAddressBlock!(ret)
self.findAddressBlock = nil
}else{
self.findAddressBlock!("")
self.findAddressBlock = nil
}
}
})
}
'iOS' 카테고리의 다른 글
[swift] Util(UIImage) (0) | 2017.12.01 |
---|---|
[swift] Util(String) (0) | 2017.12.01 |
앱스토어 버전 가져오기 (0) | 2015.09.11 |
iOS AudioSession 공부중.... (0) | 2015.05.28 |
NSDate 대해서 (0) | 2015.05.06 |