-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