【发布时间】:2018-05-02 04:14:46
【问题描述】:
我正在 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");
}
});
【问题讨论】:
-
为什么投反对票。当我尝试使用该网站进行学习时,我将被禁止进一步提问。