2016-11-22 13 views
6

逆ジオコーディングを使用しようとしたときに、このエラーメッセージが表示されました。CLGeocoderエラーです。 GEOErrorDomainコード= -3

Geocode error: Error Domain=GEOErrorDomain Code=-3 "(null)"

私のコード以下の通りです:

import CoreLocation 
geocoder.reverseGeocodeLocation(location) { (placemarks, error) in 
    if let placemarks = placemarks { 
     reverseGeocodeLocations[hash] = placemarks 
    } 
    callback(placemarks, error) 
} 

これは時間だけの時間を動作し、私は秒あたりreverseGeocode数回要求します。だから私はこのエラーメッセージは、要求や何かの限界に関連していると思いますか? リンゴのジオコード要求に関するドキュメントはありますか? 進んでいただきありがとうございます。ここ

を更新しました


import CoreLocation 

fileprivate struct ReverseGeocodeRequest { 

    private static let geocoder = CLGeocoder() 
    private static var reverseGeocodeLocations = [Int: [CLPlacemark]]() 
    private static let reverseGeocodeQueue = DispatchQueue(label: "ReverseGeocodeRequest.reverseGeocodeQueue") 

    private static var nextPriority: UInt = 0 

    fileprivate static func request(location: CLLocation, callback: @escaping ([CLPlacemark]?, Error?)->Void) { 
     let hash = location.hash 
     if let value = reverseGeocodeLocations[hash] { 
      callback(value, nil) 
     } else { 
      reverseGeocodeQueue.async { 
       guard let value = reverseGeocodeLocations[hash] else { 
        geocoder.reverseGeocodeLocation(location) { (placemarks, error) in 
         if let placemarks = placemarks { 
          reverseGeocodeLocations[hash] = placemarks 
         } 
         callback(placemarks, error) 
        } 
        return 
       } 
       callback(value, nil) 
      } 
     } 
    } 



    let priority: UInt 
    let location: CLLocation 
    let handler : ([CLPlacemark]?, Error?)->Void 

    private init (location: CLLocation, handler: @escaping ([CLPlacemark]?, Error?)->Void) { 
     ReverseGeocodeRequest.nextPriority += 1 
     self.priority = ReverseGeocodeRequest.nextPriority 
     self.location = location 
     self.handler = handler 
    } 

} 

extension ReverseGeocodeRequest: Comparable { 
    static fileprivate func < (lhs: ReverseGeocodeRequest, rhs: ReverseGeocodeRequest) -> Bool { 
     return lhs.priority < rhs.priority 
    } 
    static fileprivate func == (lhs: ReverseGeocodeRequest, rhs: ReverseGeocodeRequest) -> Bool { 
     return lhs.priority == rhs.priority 
    } 

} 


extension CLLocation { 

    func reverseGeocodeLocation(callback: @escaping ([CLPlacemark]?, Error?)->Void) { 
     ReverseGeocodeRequest.request(location: self, callback: callback) 
    } 

    func getPlaceName(callback: @escaping (Error?, String?)->Void) { 
     self.reverseGeocodeLocation { (placemarks, error) in 
      guard let placemarks = placemarks, error == nil else { 
       callback(error, nil) 
       return 
      } 
      guard let placemark = placemarks.first else { 
       callback(nil, "Mysterious place") 
       return 
      } 

      if let areaOfInterest = placemark.areasOfInterest?.first { 
       callback(nil, areaOfInterest) 
      } else if let locality = placemark.locality { 
       callback(nil, locality) 
      } else { 
       callback(nil, "On the Earth") 
      } 
     } 
    } 
} 
+0

これを解決しましたか? –

+1

@RayTsoいいえ、できませんでした。私たちが短時間に複数のリクエストをしたときにエラーが発生したようです。代わりに、キューイングと遅延更新を使用してこの問題を回避しました。 –

答えて

7

答えをどこからでも検索したところ、Appleのドキュメントにありました! :/

https://developer.apple.com/reference/corelocation/clgeocoder/1423621-reversegeocodelocation

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 passes an error object with the value network to your completion handler.

、それが実際にネットワークエラーで完了ハンドラでエラーコードをチェック:2

ホープこれは誰かに役立ちます!

+0

要求の最大数はどれですか? – Ricardo

+1

@Ricardoこの番号はAppleによって開示されていません。彼らが与える唯一の詳細は、上記の見積もりです。私は最大数のリクエストがあるとは思わないが、それらのリクエストを再帰的に実行する方法には限界があります。 –

-1

を要求するための私の全体のコードは、あなたが)(CLGeocoderレクリエーションですされています。たとえば、ループ内にCLGeocoder以外は同じエラーメッセージが表示される場合は、配列の配列をチェックするループがあります。

これが役に立ちます。

+0

回答ありがとうございますが、私はCLGeocoderに静的変数を使用しています。それは仕事ではありません。 –

+0

コードを投稿できますか? – AlexanderKaran

+0

私のコードを更新しました。 ありがとうございます。 –

関連する問題