我正在R中建立一个程序,如果我提供纬度和经度值的话,我可以得到一个位置的一些天气信息。我想使用http或HTTR包并使用GET函数。有人能向我展示使用API如何实现这一任务的R代码吗?
发布于 2018-06-21 18:12:52
如果你访问Weather Underground站点并获取API密钥(https://www.wunderground.com/weather/api/),则可以使用rwunderground
封装来封装所需的所有低级httr
功能以获取天气状况。例如,
library(rwunderground)
wx <- conditions(set_location(lat_long="40,-104"))
这将首次要求你输入你的API密钥。这将是类似的,dxxxxd3000b5xxxx
但它将是唯一的注册。每分钟和每天查询都有限制。以下是你可以访问的变量:
> wx <- conditions(set_location(lat_long="40,-104"))
[1] "Requesting:
http://api.wunderground.com/api/d7000d3860b5bf50/conditions/q/40,-104.json"
[1] "Conditions for: Wiggins, CO"
[1] "Observed at: Fort Morgan, Colorado"
[1] "Station id: KCOWIGGI11"
[1] "Time: Last Updated on June 17, 6:19 PM MDT"
> str(wx)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 1 obs. of 15 variables:
$ weather : Factor w/ 1 level "Rain": 1
$ temp : num 61
$ pct_humidity : num 92
$ wind_spd : num 8.7
$ wind_spd_gust: num 11.4
$ wind_dir : Factor w/ 1 level "NE": 1
$ pressure : num 30
$ dew_pt : num 59
$ heat_index : num NA
$ windchill : num NA
$ feelslike : num 61
$ visibility : num 10
$ UV : num 0
$ precip_1hr : num 0.05
$ precip_today : num 0.15
https://stackoverflow.com/questions/-100005479
复制相似问题