我正在使用这个雅虎天气库来获取天气信息。 https://github.com/nishanths/YWeatherAPI所以我正在使用此代码。
CLLocationDegrees Lat = _course.latitude;
CLLocationDegrees Log = _course.longitude;
CLLocation *LocationAtual=[[CLLocation alloc] initWithLatitude:Lat longitude:Log];
NSLog(@"latitude %f", LocationAtual.coordinate.latitude);
NSLog(@"longitude %f", LocationAtual.coordinate.longitude);
[[YWeatherAPI sharedManager] temperatureForCoordinate: LocationAtual
success:^(NSDictionary* result)
{
NSString* temperature = [result objectForKey:kYWAIndex];
NSLog(@"The temperature is a pleasant %@ F", result);
}
failure:^(id response, NSError* error)
{
// Yikes, something went wrong
NSLog(@"error = %@", error);
}
];
当我经过纬度和经度以下时。代码工作正常并获取天气信息。
latitude 44.983307
longitude -123.313362
但是当我传递以下信息时。我正在例外。所以它不适用于某些纬度和经度甚至lat和long是正确的,因为它在android中工作。
latitude 39.065983
longitude -76.925858
错误: -
error = Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: bad request (400)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7face9e810c0> { URL: https://query.yahooapis.com/v1/public/yql?q=select%20woeid%20from%20geo.places(1)%20where%20text%3D'Prince%20George's%20MD%20United%20States'&format=json } { status code: 400, headers {
"Access-Control-Allow-Origin" = "*";
Age = 0;
Connection = "keep-alive";
"Content-Type" = "application/json; charset=UTF-8";
Date = "Thu, 19 May 2016 12:45:27 GMT";
Server = ATS;
"Transfer-Encoding" = Identity;
Via = "https/1.1 a10.ue.bf1.yahoo.net (ApacheTrafficServer [cMsSf ])";
"X-Content-Type-Options" = nosniff;
"X-YQL-Host" = "main-bb9eeee2-0d62-11e6-aa18-d4ae52974741";
"Y-Trace" = "BAEAQAAAAAC1DsBcRpDbSAAAAAAAAAAAxeJD1VIoumEAAAAAAAAAAAAFMzFZQeTfAAUzMVlB8htSLwgkAAAAAA--";
}},
NSErrorFailingURLKey=https://query.yahooapis.com/v1/public/yql?q=select%20woeid%20from%20geo.places(1)%20where%20text%3D'Prince%20George's%20MD%20United%20States'&format=json, com.alamofire.serialization.response.error.data=<7b226572 726f7222 3a7b226c 616e6722 3a22656e 2d555322 2c226465 73637269 7074696f 6e223a22 51756572 79207379 6e746178 20657272 6f722873 29205b6c 696e6520 313a3538 206d6973 73696e67 20454f46 20617420 2773275d 227d7d>, NSLocalizedDescription=Request failed: bad request (400)}
2016-05-19 08:45:27.485 GolfSmash[22419:2146748] error = Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: bad request (400)"
请看看我错过了什么。