ios 获取天气信息的 Google API
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14618663/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Google API to Get Weather Information
提问by sample
I need to fetch the weather information based on the user's current location. Please provide me the Google API to get the weather info.
我需要根据用户的当前位置获取天气信息。请向我提供 Google API 以获取天气信息。
I am using http://www.google.com/ig/api?weather=Mumbai, but Google is returning some error:
我正在使用http://www.google.com/ig/api?weather=Mumbai,但 Google 返回了一些错误:
We're sorry...
... but your computer or network may be sending automated queries. To protect our users, we can't process your request right now.
See Google Help for more information.
我们很抱歉...
...但您的计算机或网络可能正在发送自动查询。为了保护我们的用户,我们现在无法处理您的请求。
有关详细信息,请参阅 Google 帮助。
When I looked it up on Google, I found out that Google API is down.
当我在 Google 上查找时,我发现 Google API 已关闭。
Please guide me which one is the latest Google API to get the weather info.
请指导我哪一个是最新的谷歌 API 来获取天气信息。
回答by Nitin Gohel
Hi arundhati have you Google it? i just searching in google and found best answer From :-
嗨,arundhati,你谷歌了吗?我只是在谷歌搜索并找到了最佳答案:-
Including Weather Information, iPhone App, Weather API
Check for the Best Weather API,
检查最佳天气 API,
Read the blog tutorial with sample code for
阅读带有示例代码的博客教程
Adding Local Weather Conditions To Your App (Part 2/2: Accessing Google's XML Weather API)
向您的应用程序添加本地天气条件(第 2/2 部分:访问 Google 的 XML Weather API)
Integrating weather information in iphone
Hope its helps you :)
希望它对你有帮助:)
This is a Demo of Weather API iphone
这是天气 API iphone 的演示
https://github.com/elc/ICB_LocalWeather
https://github.com/elc/ICB_LocalWeather
Example: http://api.wunderground.com/auto/wui/geo/GeoLookupXML/index.xml?query=90210
示例:http: //api.wunderground.com/auto/wui/geo/GeoLookupXML/index.xml?query=90210
回答by kukat
Google terminate Weather API permanently...
Google 永久终止 Weather API...
Alternatively you can use:
或者,您可以使用:
回答by Bhushan Firake
The best weather API is here.
最好的天气 API 在这里。
Sample JSON response from them is as below:
他们的示例 JSON 响应如下:
{
"response": {
"version": "0.1",
"termsofService": "http://www.wunderground.com/weather/api/d/terms.html",
"features": {
"conditions": 1
}
},
"current_observation": {
"image": {
"url": "http://icons-ak.wxug.com/graphics/wu2/logo_130x80.png",
"title": "Weather Underground",
"link": "http://www.wunderground.com"
},
"display_location": {
"full": "San Francisco, CA",
"city": "San Francisco",
"state": "CA",
"state_name": "California",
"country": "US",
"country_iso3166": "US",
"zip": "94101",
"latitude": "37.77500916",
"longitude": "-122.41825867",
"elevation": "47.00000000"
},
"observation_location": {
"full": "SOMA - Near Van Ness, San Francisco, California",
"city": "SOMA - Near Van Ness, San Francisco",
"state": "California",
"country": "US",
"country_iso3166": "US",
"latitude": "37.773285",
"longitude": "-122.417725",
"elevation": "49 ft"
},
"estimated": {},
"station_id": "KCASANFR58",
"observation_time": "Last Updated on June 27, 5:27 PM PDT",
"observation_time_rfc822": "Wed, 27 Jun 2012 17:27:13 -0700",
"observation_epoch": "1340843233",
"local_time_rfc822": "Wed, 27 Jun 2012 17:27:14 -0700",
"local_epoch": "1340843234",
"local_tz_short": "PDT",
"local_tz_long": "America/Los_Angeles",
"local_tz_offset": "-0700",
"weather": "Partly Cloudy",
"temperature_string": "66.3 F (19.1 C)",
"temp_f": 66.3,
"temp_c": 19.1,
"relative_humidity": "65%",
"wind_string": "From the NNW at 22.0 MPH Gusting to 28.0 MPH",
"wind_dir": "NNW",
"wind_degrees": 346,
"wind_mph": 22.0,
"wind_gust_mph": "28.0",
"wind_kph": 35.4,
"wind_gust_kph": "45.1",
"pressure_mb": "1013",
"pressure_in": "29.93",
"pressure_trend": "+",
"dewpoint_string": "54 F (12 C)",
"dewpoint_f": 54,
"dewpoint_c": 12,
"heat_index_string": "NA",
"heat_index_f": "NA",
"heat_index_c": "NA",
"windchill_string": "NA",
"windchill_f": "NA",
"windchill_c": "NA",
"feelslike_string": "66.3 F (19.1 C)",
"feelslike_f": "66.3",
"feelslike_c": "19.1",
"visibility_mi": "10.0",
"visibility_km": "16.1",
"solarradiation": "",
"UV": "5",
"precip_1hr_string": "0.00 in ( 0 mm)",
"precip_1hr_in": "0.00",
"precip_1hr_metric": " 0",
"precip_today_string": "0.00 in (0 mm)",
"precip_today_in": "0.00",
"precip_today_metric": "0",
"icon": "partlycloudy",
"icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif",
"forecast_url": "http://www.wunderground.com/US/CA/San_Francisco.html",
"history_url": "http://www.wunderground.com/history/airport/KCASANFR58/2012/6/27/DailyHistory.html",
"ob_url": "http://www.wunderground.com/cgi-bin/findweather/getForecast?query=37.773285,-122.417725"
}
}
回答by Anil
Google Weather API is down. Check out the following alternatives:
Google Weather API 已关闭。查看以下替代方案:
I've been using the first link. Its free like Open Street Maps.
我一直在使用第一个链接。它像开放街道地图一样免费。
EDIT:
编辑:
Here's the basic code to get the JSON:
这是获取 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
}
Add that to the viewDidLoad
将其添加到 viewDidLoad