Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Wunderground地理定位使用$.ajax不附加到HTML_Javascript_Json_Ajax_Geolocation - Fatal编程技术网

Javascript Wunderground地理定位使用$.ajax不附加到HTML

Javascript Wunderground地理定位使用$.ajax不附加到HTML,javascript,json,ajax,geolocation,Javascript,Json,Ajax,Geolocation,我正在尝试使用$.ajax来使用地理定位将天气数据输入到来自Wunderground的页面中。当我使用简单的vanilla JS将我的位置手动输入到代码中时,我能够成功地将天气数据输入到我的页面中,但我想更进一步。我正在运行以下代码,并收到一个警告框,询问位置,但单击“确定”后,我的HTML没有代码更新。在开发工具中打开控制台时,我没有看到任何错误消息 var Geo={}; if (navigator.geolocation) { navigator.geolocation.getCurren

我正在尝试使用$.ajax来使用地理定位将天气数据输入到来自Wunderground的页面中。当我使用简单的vanilla JS将我的位置手动输入到代码中时,我能够成功地将天气数据输入到我的页面中,但我想更进一步。我正在运行以下代码,并收到一个警告框,询问位置,但单击“确定”后,我的HTML没有代码更新。在开发工具中打开控制台时,我没有看到任何错误消息

var Geo={};
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(successGeo,error);
}
else {
alert('Geolocation is not supported');
}

function error() {
alert("Cant find you");
}

function successGeo(position) {
      Geo.lat = position.coords.latitude;
      Geo.lng = position.coords.longitude;
}

function showPosition(position) {
    var geoLat = position.coords.latitude;
    var geoLong = position.coords.longitude;
    var key = "8704dded63fc077d";
    var ForecastURL = "http://api.wunderground.com/api/"; + key + "/forecast/q/" + geoLat + "," + geoLong + ".json";
    var WeatherURL = "http://api.wunderground.com/api/"; + key + "/conditions/q/" + geoLat + "," + geoLong + ".json";




  $.ajax({
        url : WeatherURL,
        dataType : "jsonp",
        success : function(parsed_json) {
        var temp_f = parsed_json['current_observation']['temp_f'];
        document.getElementById("currentTemp").innerHTML = temp_f;
        }
    });

  $.ajax({
        url : ForecastURL,
        dataType : "jsonp",
        success : function(parsed_json) {
        var fore_high = parsed_json['forecast']['simpleforecast']['forecastday'][0]['high']['fahrenheit'];
        var fore_low = parsed_json['forecast']['simpleforecast']['forecastday'][0]['low']['fahrenheit'];
        document.getElementById("high1").innerHTML = fore_high;
        document.getElementById("low1").innerHTML = fore_low;

        }
    });    

} //ends showposition function
我在index.html的页脚中设置了一些div元素,以便确认这些元素正在更新。稍后我会更担心样式和对齐

<footer> <!--//contains ajax weather data-->
<div id="high1"></div>
<div id="current_temp"></div>
<div id="low1"></div>
</footer>


我很困惑,为什么我不能得到回应,特别是因为我没有在控制台中发现任何错误。

你在哪里/什么时候调用
showPosition
?到目前为止,您的
getCurrentPosition
正在回调
successGeo
,而不是
showPosition
好的捕获。我有一些旧代码,在复制和粘贴的过程中忘记了更改函数名和调用它们的时间。谢谢你的帮助。当声明ForecastURL和WeatherURL变量时,我还意识到在连接中有一个额外的“;”。