简体   繁体   English

openweathermap API返回错误信息

[英]openweathermap api return wrong information

I am making a weather app using api from openweathermap. 我正在使用来自openweathermap的api制作天气应用。 It worked but It showed the wrong information about my place and the temperature. 可以,但是显示关于我的位置和温度的错误信息。 Here the code: 这里的代码:

<h1>weather forcast</h1>
<button id="btn">view</button>
<h2 id="place"></h2>
<h3 id="description"></h3>
<p id="temp"></p>

and the script: 和脚本:

var getWeather = function(data) {
$.getJSON('http://api.openweathermap.org/data/2.5/weather', {
    lat: data.loc.split(",")[0],
    lon: data.loc.split(",")[1],
    appid: "0596efa13d750207ba4eff57342a81dd" // change this
}, showWeather, 'jsonp');
};

var showWeather = function(data) {
$("#test").text("I AM CHANGED. THANKS!")
$("#temp").text(data.main.temp)
$("#description").text(data.weather[0].description)
$("#place").text(data.name)
};

$(document).ready(function() {
$("#btn").click(function() {
    $.getJSON('http://ipinfo.io/json', getWeather, 'jsonp')
})
})

Some people told me the api may return the info about the nearest place where the exchange/isp is but I know the result is wrong because it is a completely strange name. 有人告诉我api可能会返回有关exchange / isp的最近位置的信息,但我知道结果是错误的,因为它是一个完全陌生的名称。 And the temperature, as I tried, it showed 287.944 , it is not the right Fahrenheit or Celcius according to my location's info. 根据我的位置信息,温度(如我所试)显示为287.944 ,这不是正确的华氏温度或摄氏温度。 In fact, the temp now in my location is 60 F or 15 C 实际上,现在我所在位置的温度为60 F15 C

The temperature is in Kelvin because you didn't provide any parameter like units=imperial or units=metric. 温度以开尔文为单位,因为您未提供任何参数,例如unit = imperial或units = metric。 The name is of the nearest station where the weather params are coming from. 该名称是天气参数来自的最近车站。

Enrico 恩里科

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM