CLGeoCoder

영 yyyng·2022년 8월 22일
0

Swift

목록 보기
9/9
post-thumbnail
							//좌표값 coordinate2D 타입으로 해줌
func convertToAddressWith(coordinate: CLLocationCoordinate2D) {
            let location = CLLocation(latitude: coordinate.latitude, longitude: coordinate.longitude)
            			//CLGeocoder 생성
            let geocoder = CLGeocoder()
            			//locale 설정 (옵션인듯)
            let locale = Locale(identifier: "Ko-kr")
            geocoder.reverseGeocodeLocation(location, preferredLocale: locale) { [weak self] placemarks, _ in
            							//.first, .last 변경해봤는데 무슨차이인지 모르겠음
                guard let placemarks = placemarks?.first,
                      let dong = placemarks.subLocality,
                      let city = placemarks.locality
                else { return }
                DispatchQueue.main.async {
                self?.locationLabel.text = "\(city), \(dong)"
           
            }
        }
    }
profile
yyyng2.github.io

0개의 댓글