위치 권한 허용을 받고 현재 위치 정보를 CLLocationCoordinate2D
instance로 저장한 뒤, 해당 위치를 중심으로 MKMapView
에 나타내도록 했다.
동일 프로젝트를 각 디바이스에서 실행하면 다음과 같은 결과를 보여준다.
6S | iOS 15.7.8 | ||
---|---|---|---|
12 Pro Max | iOS 16.6 |
---|---|
12 Pro Max에서는 문제 없던 지도 로딩이 6S에서는 화면을 수도권이 다 보일 정도로 핀치 아웃해야 겨우 지도 렌더링이 진행되고 있음을 확인할 수 있었다.
6S에서만 다음과 같은 에러메시지가 나타났다.
Failed to load key: -7: GEOErrorDomain
아무리 검색해도 GEOErrorDomain 정보가 안나와서 MKMapView
의 Delegate를 활용해 에러를 출력해보기로 했다.
extension ViewController: MKMapViewDelegate {
//for checking when map rendering succeeds
func mapViewDidFailLoadingMap(_ mapView: MKMapView, withError error: Error) {
print("Error: ", error.localizedDescription)
}
func mapViewWillStartLoadingMap(_ mapView: MKMapView) {
print("MapView Loading Starts!!!")
}
func mapViewDidFinishLoadingMap(_ mapView: MKMapView) {
print("MapView Finished Loading Map!!!")
}
}
콘솔 출력 결과는 다음과 같다.
Error: The operation couldn’t be completed. (GEOErrorDomain error -7.)
역시나 답이 안나오면 구글링을 엄청 해봐야 한다.
- iOS GEOErrorDomain error code 7
- swift GEOErrorDomain
- iPhone 6S GEOErrorDomain error
- etc...
검색 결과를 찾던 중 stackOverflow에서 이런 글이 있었다.
StackOverflow ~ Geocode error: Error Domain=GEOErrorDomain Code=-8 "(null)"
CLGeocoder를 활용하던 중 에러가 비슷하게 나타남을 확인할 수 있었다.
링크 답변을 타고 가면 이런 글이 나타났다.
StackOverflow ~ CLGeocoder reverseGeocodeLocation error -8
마찬가지로 CLGeocoder 활용 중 위 링크와 동일한 에러를 발견함을 알 수 있었다.
따라서 다음과 같이 검색을 다시 해보았다.
CLGeocoder Error
그리고 찾은 공식 문서에 다음과 같이 작성이 되어있다.
CLGeocoder
An interface for converting between geographic coordinates and place names.
The CLGeocoder class provides services for converting between a coordinate (specified as a latitude and longitude) and the user-friendly representation of that coordinate. A user-friendly representation of the coordinate typically consists of the street, city, state, and country or region information corresponding to the given location, but it may also contain a relevant point of interest, landmarks, or other identifying information. A geocoder object is a single-shot object that works with a network-based service to look up placemark information for its specified coordinate value.
위치 정보와 실제 지명 이름을 mapping하고 유저에게 편하게 보여줄 수 있도록 해주는 인터페이스 역할을 한다. 특정 위치 정보를 활용하려는 네트워크 서비스와 함께 활용될 수 있다.
Tips for Using a Geocoder Object
Apps must be conscious of how they use geocoding. Geocoding requests are rate-limited for each app, so making too many requests in a short period of time may cause some of the requests to fail. (When the maximum rate is exceeded, the geocoder returns an error object with theCLError.Code.network
error to the associated completion handler.) Here are some rules of thumb for using this class effectively:
너무 많은 네트워크 request가 가면 request를 fail 처리할 수 있다. 이를 위한 error code를 확인하러 CLError.Code 정의를 확인해봤다.
CLError.Code
Error codes returned by the location manager object.
enum 타입으로 수많은 에러 케이스를 담당하고 있다.
Getting general errors
- case locationUnknown
A constant that indicates the location manager was unable to obtain a location value right now.- case denied
A constant that indicates the user denied access to the location service.- case promptDeclined
A constant that indicates the user didn’t grant the requested temporary authorization.- case network
A constant that indicates the network was unavailable or a network error occurred.- case headingFailure
A constant that indicates the location manager can’t determine the heading.- case rangingUnavailable
A constant that indicates ranging is disabled.- case rangingFailure
A constant that indicates a general ranging error occurred.
Getting region monitoring errors- case regionMonitoringDenied
A constant that indicates the user denied access to the region monitoring service.- case regionMonitoringFailure
A constant that indicates the location manager failed to monitor a registered region.- case regionMonitoringSetupDelayed
A constant that indicates Core Location failed to initialize the region monitoring feature.- case regionMonitoringResponseDelayed
A constant that indicates Core Location will deliver events but they may be delayed.
Getting geocoding errors
- case geocodeCanceled
A constant that indicates the geocode request was canceled.- case geocodeFoundNoResult
A constant that indicates the geocode request yielded no result.- case geocodeFoundPartialResult
A constant that indicates the geocode request yielded a partial result.
Getting deffered location update errors
- case deferredFailed
A constant that indicates the location manager didn’t enter deferred mode for an unknown reason.- case deferredCanceled
A constant that indicates your app or the location manager canceled the request for deferred updates.- case deferredAccuracyTooLow
A constant that indicates deferred mode isn’t supported for the requested accuracy.- case deferredDistanceFiltered
A constant that indicates deferred mode doesn’t support distance filters.- case deferredNotUpdatingLocation
A constant that indicates the location manager didn’t enter deferred mode because location updates were already disabled or paused.
Enumeration Cases
- case historicalLocationError
에러코드가 7인 것을 찾아보니 다음과 같았다.
CLError.Code.regionMonitoringResponseDelayed
A constant that indicates Core Location will deliver events but they may be delayed.
Core Location이 현재 위치를 가져오고 있지만 delay되고 있음을 알려준다.
The user information dictionary might contain an alternate region that you can monitor instead. Use
kCLErrorUserInfoAlternateRegionKey
to retrieve theCLRegion
object.
모니터링 목적의 CLRegion
을 얻을 수 있는 key를 error에서 얻을 수 있다.
CoreLocation
및 MapKit
관련 에러는CLError
를 찾아보면 해당 case를 찾아볼 수 있을 것 같다.