Reverse Geocoding

sanghee·2022년 5월 2일
0

🍀인턴 스터디

목록 보기
9/12

**Converting Between Coordinates and User-Friendly Place Names**

  • 리버스 지오코딩: 지리적 좌표로 설명된 위치를 사람이 읽을 수 있는 주소 또는 장소 이름으로 변환하는 과정

  • 위도와 경도값보다는 장소명이 사용자 친화적이다.

    • 사용자는 위도와 경도로 이루어진 위치값보다 위치를 설명하는 이름(거리명, 도시명)에 더 익숙하다.
  • CLLocationManager나 CLGeocoder 클래스를 사용하여 위치값과 이름을 변환할 수 있다.

CLPlacemark

  • 국가, 도시명, 지역명, 거리명, 우편 번호, 산, 강, 랜드마크 이름 등 위치를 설명하기 위한 속성들을 가진다.

CLGeocoder

  • 지리적 좌표와 장소명 간의 변환을 위한 인터페이스이다.
  • 여러 지오코더 객체를 생성할 수 있지만, Apple은 수행할 수 있는 변환 수를 제한한다. 짧은 시간에 너무 많은 변환을 시도한다면 일부 실패할 수 있다.

좌표 → 장소이름

  • reverseGeocodeLocation(_: completionHandler:) 메서드를 활용한다.
  • placemark에는 다음과 같은 속성이 있다.
    • name: 장소 표시 이름. OO동 000-000
    • country: 국가 또는 지역 이름
    • postalCode: 우편번호
    • administrativeArea: 시/도
    • locality: 도시
    • timeZone: 연결된 시간대
    • ocean: 바다 이름
let geocoder = CLGeocoder()
            
geocoder.reverseGeocodeLocation(location) { placemarks, error in
    guard error == nil, let placemark = placemarks?.first else { return }
    print(placemark.name)
}

장소이름 → 좌표

  • geocodeAddressString(_: completionHandler:) 메서드를 활용한다.
let geocoder = CLGeocoder()

geocoder.geocodeAddressString(address) { placemarks, error in
    guard error == nil, let location = placemarks?.first?.location else { return }
    print(location)
}



참고문서

**Converting Between Coordinates and User-Friendly Place Names**

**reverseGeocodeLocation**

profile
👩‍💻

0개의 댓글