sam*_*ple 6 iphone google-weather-api ios
我需要根据用户的当前位置获取天气信息。请向我提供 Google API 以获取天气信息。
我正在使用http://www.google.com/ig/api?weather=Mumbai,但 Google 返回了一些错误:
我们很抱歉...
...但您的计算机或网络可能正在发送自动查询。为了保护我们的用户,我们现在无法处理您的请求。
有关详细信息,请参阅 Google 帮助。
当我在 Google 上查找时,我发现 Google API 已关闭。
请指导我哪一个是最新的谷歌 API 来获取天气信息。
Google 天气 API 已关闭。查看以下替代方案:
我一直在使用第一个链接。它像开放街道地图一样免费。
编辑:
以下是获取 JSON 的基本代码:
NSError *error = nil;
NSData *jsonData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://openweathermap.org/data/2.1/find/city?lat=32.85190&lon=57.65878&cnt=1&type=JSON"]];
if (jsonData) {
id jsonObjects = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
if (error) {
NSLog(@"error is %@", [error localizedDescription]);
// Handle Error and return
return;
}
NSArray *keys = [jsonObjects allKeys];
// values in foreach loopDic]
for (NSString *key in keys) {
NSLog(@"%@ is %@",key, [jsonObjects objectForKey:key]);
}
} else {
// Handle Error
}
Run Code Online (Sandbox Code Playgroud)
将其添加到viewDidLoad
| 归档时间: |
|
| 查看次数: |
44179 次 |
| 最近记录: |