我正在尝试制作一个使用 openweathermap api 来显示用户的城市和当地温度的页面,不幸的是它似乎没有处理 JSON api 并且什么也没做。据我所知,我的代码很好,所以我不明白出了什么问题。
这是 jsfiddle 链接和 javscript 代码:
https ://jsfiddle.net/qo2h1L9e/2/
$(document).ready(function() {
var data;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var lat = position.coords.latitude;
var lon = position.coords.longitude;
console.log(lat);
console.log(lon);
console.log("api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&APPID=4907e373098f091c293b36b92d8f0886");
$.getJSON("api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&APPID=4907e373098f091c293b36b92d8f0886", function(json) {
data = json;
console.log(data.name);
$("#city").text(data.name);
});
});
}
});