使用Openweather JSON API,如何获取温度?

Using Openweather JSON API,how to fetch the temperature?

使用 Openweather JSON API 通过传递 Latitude, Longitude ,我正在获取数据。我需要获取华氏度的当前温度

基于 Openweather 上提供的示例 api,我正在从现场读取数据:deg

示例:

"wind":{"speed":5.1,"deg":310}

学位:310。

我正在读取的值不正确。具体值是多少,我需要读读学位。

代码示例

我家附近的天气是 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>

说明

将单位设置为英制,这样默认温度将以华氏度 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