Reputation: 169
I am making a weather app using api from openweathermap. 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. And the temperature, as I tried, it showed 287.944
, it is not the right Fahrenheit or Celcius according to my location's info. In fact, the temp now in my location is 60 F
or 15 C
Upvotes: 0
Views: 762
Reputation: 115
The temperature is in Kelvin because you didn't provide any parameter like units=imperial or units=metric. The name is of the nearest station where the weather params are coming from.
Enrico
Upvotes: 1