【发布时间】:2017-07-17 11:19:41
【问题描述】:
通过传递 Latitude, Longitude 使用 Openweather JSON API,我正在获取数据。我需要获取当前华氏温度
基于 Openweather 上提供的示例 api,我正在从现场读取数据:deg
例子:
“风”:{“速度”:5.1,“度”:310}
度数:310。
我正在阅读的值不正确。具体数值是多少,我需要读读度数。
【问题讨论】:
标签: jquery json openweathermap
通过传递 Latitude, Longitude 使用 Openweather JSON API,我正在获取数据。我需要获取当前华氏温度
基于 Openweather 上提供的示例 api,我正在从现场读取数据:deg
例子:
“风”:{“速度”:5.1,“度”:310}
度数:310。
我正在阅读的值不正确。具体数值是多少,我需要读读度数。
【问题讨论】:
标签: jquery json openweathermap
我附近的天气是 35 度,反应是 32 度。
let API_KEY = 'e0a3dfaead51bbda58049371909fe21f';
function getWeather(latitude, longtitude) {
$.ajax({
url: 'http://api.openweathermap.org/data/2.5/weather',
data: {
lat: latitude,
lon: longtitude,
units: 'imperial',
APPID: API_KEY
},
success: data => {
console.log(data["main"]["temp"] + " F");
}
})
}
getWeather(40.863372, -74.113181);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
将单位设置为英制,以便默认温度以 Farenheight units=imperial 返回,当前温度位于 main.temp 下
文档说这是一个示例响应:
{
"coord": {
"lon": 145.77,
"lat": -16.92
},
"weather": [{
"id": 803,
"main": "Clouds",
"description": "broken clouds",
"icon": "04n"
}],
"base": "cmc stations",
"main": {
"temp": 293.25,
"pressure": 1019,
"humidity": 83,
"temp_min": 289.82,
"temp_max": 295.37
},
"wind": {
"speed": 5.1,
"deg": 150
},
"clouds": {
"all": 75
},
"rain": {
"3h": 3
},
"dt": 1435658272,
"sys": {
"type": 1,
"id": 8166,
"message": 0.0166,
"country": "AU",
"sunrise": 1435610796,
"sunset": 1435650870
},
"id": 2172797,
"name": "Cairns",
"cod": 200
}
当前天气在main:
"main": {
"temp": 306.15, //current temperature
"pressure": 1013,
"humidity": 44,
"temp_min": 306, //min current temperature in the city
"temp_max": 306 //max current temperature in the city
},
要设置温度单位,请使用units= 参数:
api.openweathermap.org/data/2.5/find?q=London&units=imperial
更多信息来自他们的docs
还有你可以使用的所有参数here
【讨论】:
units=metric。你在哪个位置测试?? @goofyui