wundergroundを使用して、現在の場所に Weather API を使用しています。現在の場所の都市が API で利用できない場合、アプリがクラッシュします。現在の場所の都市が利用できない場合、近くの天気の場所の都市をリダイレクトしたいと考えています。
ここに私のコードがあります、
-(void) geoCodeUsingAddress:(NSString *)address
{
NSString *esc_addr = [address stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
NSString *urlString =[NSString stringWithFormat:@"http://api.wunderground.com/api/8e2edc55aaf7cfa7/geolookup/conditions/forecast/q/%@.json",esc_addr];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
NSData *response1 = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSDictionary *alldicdata=[NSJSONSerialization JSONObjectWithData:response1 options:0 error:nil];
NSDictionary *forecast=[alldicdata objectForKey:@"forecast"];
NSDictionary *simpleforecast=[forecast objectForKey:@"simpleforecast"];
NSArray *arrofforecastday=[simpleforecast objectForKey:@"forecastday"];
NSMutableArray *dataStore1=[[NSMutableArray alloc]init];
for(NSDictionary *dict in arrofforecastday)
{
NSMutableDictionary *data=[[NSMutableDictionary alloc] init];
[data setObject:[dict objectForKey:@"conditions"] forKey:@"conditions"];
利用可能な都市の近くをリダイレクトまたは検索する方法はありますか。誰か助けてください。