0
我試圖通過在URL中提供地點id來獲取地點詳細信息,如下所示。錯誤域= NSURLErrorDomain代碼= -999「取消」
func findingPlaceDetailsFromPlaceId(id : String){
var urlString = "https://maps.googleapis.com/maps/api/place/details/json?placeid=\(id)&key=\(apiServerKey)"
urlString = urlString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!
//println(urlString)
if placesTask.taskIdentifier > 0 && placesTask.state == .Running {
placesTask.cancel()
}
UIApplication.sharedApplication().networkActivityIndicatorVisible = true
placesTask = session.dataTaskWithURL(NSURL(string: urlString)!) {data, response, error in
println(error)
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
if let json = NSJSONSerialization.JSONObjectWithData(data, options:nil, error:nil) as? NSDictionary {
if let results = json["result"] as? NSArray {
println(results.count)
for rawPlace:AnyObject in results {
let dict = rawPlace as! NSDictionary
if let location = dict["geometry"]?["location"] as? NSDictionary{
let lat = location["lat"] as! CLLocationDegrees
let long = location["lng"] as! CLLocationDegrees
self.coordinate = CLLocationCoordinate2DMake(lat, long)
}
}
}
}
dispatch_async(dispatch_get_main_queue()) {
}
}
self.placesTask.resume()
}
給定的url是有效的。如果我把相同的網址在谷歌我得到有效的結果,但是當我運行它在我的應用程序它顯示「錯誤域= NSURLErrorDomain代碼= -999」取消「
您似乎已取消會話。如果placesTask.taskIdentifier> 0 && placesTask.state ==.Running { placesTask.cancel() } –
請注意這兩行。這應該是真正的答案。 – gnasher729