目前正在建立本地天气显示应用程序;我想我开始编写一个函数来检索然后显示获取的地理位置数据,以测试我实际上是在获取它。 This CodePen是我迄今为止所拥有的。这是相关的JavaScript(请注意,jQuery在笔中啰嗦):
function giveResponse(res){
document.getElementByID("cond").innerHTML = res;
}
function getLoc(){
var response;
if('geolocation' in navigator) {
requestlocation();
}
else {
response = "Geolocation not supported by your browser."
giveResponse(response);
}
function reqLoc() {
var options = {
enableHighAccuracy: false,
timeout:5000,
maximumAge:0
};
function success(pos){
var lng = pos.coords.longitude;
var lat = pos.coords.latitude;
response = "Your location is " + lng + lat + " .";
giveResponse(response);
}
function error(err){
response = "There was an error retrieving your location."
giveResponse(response);
}
navigator.geolocation.getCurrentPosition(success, error, options);
}
}
$(document).ready(function(){
getLoc();
});
从笔中可以看出,cond元素没有显示我描述的错误行为,或者根本没有显示任何行为。我错过了什么?