2016-04-09 18 views
0

每當用戶使用我的應用程序進行搜索時,它將返回最多100個結果的數組。我需要對每個索引進行地理編碼(每個索引都有lat和lon),並在地圖上放置一個標記。來自太多請求的NSURLSession和地理編碼器錯誤,解決方案是什麼?

我也需要使用NSURLSession顯示一個https。然後我在指定的標記位置顯示每個圖像。一切工作爲較低的數字 「精」,但是我得到兩個顯著錯誤:

1)對於圖像的東西:

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802) 

2)對於地理編碼:

geoCoder error probably too many requests Optional(Error Domain=kCLErrorDomain Code=2 "(null)") 

我的猜測我的要求太多了,蘋果有限制。那我該如何解決這個問題?當然有辦法做到這一點,或者可能是一種不同的方法?這裏是顯示圖像的代碼:

extension UIImageView { 
    public func imageFromUrl(urlString: String) { 
     if let url = NSURL(string: urlString) { 
      let request = NSURLRequest(URL: url) 
      NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) { 
       (response: NSURLResponse?, data: NSData?, error: NSError?) -> Void in 
       if let imageData = data as NSData? { 
        self.image = UIImage(data: imageData) 
       } 
      } 
     } 
    } 
} 

這裏是地理編碼器的代碼:

for i in (0 ..< tbc.categorizedArray.count) { 

       //make sure that the specified index actually has a geoLon and geoLat 
       if var longitude :Double = tbc.categorizedArray[i]["geoLon"] as? Double { 
        longitude = tbc.categorizedArray[i]["geoLon"] as! Double 
        let latitude :Double = tbc.categorizedArray[i]["geoLat"] as! Double 

        //if it does, save it's location 
        let location = CLLocation(latitude: latitude, longitude: longitude) 

        //reverseGeoCode it's location 
        CLGeocoder().reverseGeocodeLocation(location, completionHandler: { 
         placemarks, error in 
         if error != nil { 
          print("geoCoder error probably too many requests \(error)") 
          return 
         } 

         //place the markers 
         if let placemarks = placemarks { 
          let placemark = placemarks[0] 
          // Add annotation 
          let annotation = MKPointAnnotation() 
          annotation.title = tbc.categorizedArray[i]["screenname"] as? String 
          annotation.subtitle = tbc.categorizedArray[i]["userPost"] as? String 
          if let location = placemark.location { 
           annotation.coordinate = location.coordinate 
           // Display the annotation 
           self.mapView.showAnnotations([annotation], animated: true) 
           self.mapView.selectAnnotation(annotation, animated: true) 
          } 
         } 
        }) 
       } 

回答

1

-9802是一個應用程序傳輸安全問題。檢查你的證書。

不知道geocoder問題。

相關問題