Ask*_*pps 3 api xcode google-api weather
我想尝试制作一个天气应用...但我如何获取天气信息并在我的应用中使用它们?
我听说过Google IPA但是如何使用它?
首先选择最适合您的天气API:https: //stackoverflow.com/questions/507441/best-weather-apis
大多数API(包括Google)都会以XML格式返回结果.
快速编写示例代码,帮助您开始使用Google Weather API:
NSString * location = @"Amsterdam";
NSString * address = @"http://www.google.co.uk/ig/api?weather=";
NSString * request = [NSString stringWithFormat:@"%@%@",address,location];
NSURL * URL = [NSURL URLWithString:request];
NSError * error;
NSString* XML = [NSString stringWithContentsOfURL:URL encoding:NSASCIIStringEncoding error:&error];
// Extract current temperature the 'dirty' way
NSString * temp = [[[[XML componentsSeparatedByString:@"temp_c data=\""] objectAtIndex:1] componentsSeparatedByString:@"\""] objectAtIndex:0];
NSLog(@"It's currently %@ degree in %@.", temp, location);
// Parse the XML with NSXMLDocument to extract the data properly
NSXMLDocument * doc = [[NSXMLDocument alloc] initWithXMLString:XML options:0 error:NULL];
Run Code Online (Sandbox Code Playgroud)
输出:
目前在阿姆斯特丹有14度.
归档时间: |
|
查看次数: |
7545 次 |
最近记录: |