0

openweathermap の API を使って天気アプリを作っています。それは機能しましたが、私の場所と気温について間違った情報を示しました. ここにコード:

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

そしてスクリプト:

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')
})
})

一部の人々は、API が取引所/ISP がある最寄りの場所に関する情報を返す可能性があると言いましたが、まったく奇妙な名前であるため、結果が間違っていることはわかっています。そして、私が試したように、温度は、287.944私の場所の情報によると、正しい華氏または摂氏ではありませんでした。実際、私の場所の現在の温度60 F15 C

4

1 に答える 1