-1
我在FCC上构建了一个天气应用程序,我因为我的代码无法正常工作而卡住了。我没有收到浏览器访问我的位置的弹出式请求。 我在我的button.click
函数中封装了该弹出式请求。 我是新手,我感到非常沮丧。我需要帮助!!
这里是我的代码:
var Api= "https://fcc-weather-api.glitch.me/api/current?";
$(document).ready(function(){
$("button").click(function(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var lat = "lat=" + position.coords.latitude ;
var lon = "lon=" + position.coords.longitude;
$.get(Api+lat+"&"+ lon, function(result){
$("#city").text(result.main.name);
$("#country").text(result.sys.country);
$("#weather").text(result.weather[0].main);
$("#w-icon").text(result.weather[0].icon);
$("#temp").text(result.main.temp);
$("humidity").text(result.main.humidity);
});
});
});
else {
console.log ("Geolocation is not supported by this browser");
}
});
https://codepen.io/Ojomiba/pen/dVgQeQ
为什么投票。当我尝试使用该网站进行学习时,我将被禁止询问更多问题。 – user8953638