获取天气信息的 Google API

sam*_*ple 6 iphone google-weather-api ios

我需要根据用户的当前位置获取天气信息。请向我提供 Google API 以获取天气信息。

我正在使用http://www.google.com/ig/api?weather=Mumbai,但 Google 返回了一些错误:

我们很抱歉...

...但您的计算机或网络可能正在发送自动查询。为了保护我们的用户,我们现在无法处理您的请求。

有关详细信息,请参阅 Google 帮助。

当我在 Google 上查找时,我发现 Google API 已关闭。

请指导我哪一个是最新的谷歌 API 来获取天气信息。

kuk*_*kat 5

Google 永久终止 Weather API...

或者,您可以使用:

  1. 奇境API
  2. 雅虎API


Ani*_*nil 3

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