如何解决使用IP API的输出作为Weather API中的输入参数来显示城市天气
请我需要帮助我的人,我是jquery的新手,我将永远感谢您的帮助。 我有一个IP API,其中我将“城市”作为输出之一。我的目标是在openweather API中将其作为输入传递,并获取任何城市的天气。 尽管我从IP API获取输出,但从天气API中未获取任何数据,但始终收到此错误https://api.openweathermap.org/data/2.5/weather?q=undefinedundefined&`appid`=371f15346191ae114ca4ab11f4db4e2f错误响应] 1
这是我正在使用的代码,但到目前为止,我仅能成功地从IP API获取数据
// Weather
$(document).ready(function() {
var key = '3e4hxdke3eryjs';
$.ajax({
type: 'GET',url: 'https://api.ipregistry.co/'+ '?key=' + key,dataType: 'json',cache: true,success: function() {
var city = city;
var code = code;
var latitude = latitude;
var longitude = longitude;
console.log(city + ' ' + code + ' ' + latitude + ' ' + longitude);
console.log('success!');
$.ajax({
//url: "http://api.openweathermap.org/data/2.5/weather?q=Lagos,Nigeria&appid=371f15346191ae114ca4ab11f4db4e2f",url:"https://api.openweathermap.org/data/2.5/weather?q="+city+code+"&appid=371f15346191ae114ca4ab11f4db4e2f",success: function(data){
// [0 Kalvin = -273.15 Celsius] Conversion (k to c);
var cel=data.main.temp - 273.15;
$('#weatherName').html(data.name);
$('#weatherImg').attr('src','https://openweathermap.org/img/w/'+data.weather[0].icon+'.png');
$('#weatherCelsius').html(Math.round(cel) +'' + ' ℃');
$('#weatherCloudiness').html(data.weather[0].description);
}
});
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
使用openweather API获取城市的天气,您可以使用“ city”或/和两个字母的“国家/地区代码”作为输入参数,而这些参数都是从IP API给出的
谢谢大家的帮助
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。