天气Jquery wunderground获取空数据

时间:2015-12-18 11:57:01

标签: jquery

var videoURL = NSURL(string: filePath)

我不认为有错误,但我不知道为什么我得到空的天气数据wunderground,这是我第一次使用这个wunderground。我想得到天气数据,我得到地理位置但是我们有空数据

1 个答案:

答案 0 :(得分:0)

这将是一次纠正"尝试"解决你的问题,但不是一个完整的答案。 geoLocation API是异步的,因此您需要以不同的方式使用。而且你有很多语法错误。我很惊讶它没有给你。你没有打电话给fetch()

$(document).ready(function(load) {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  } else { 
    $("#demo").html("Geolocation is not supported by this browser.");
  }
  function showPosition(position) {
    var location = position.coords.latitude + "," + position.coords.longitude;
    var dmJSON = "https://api.wunderground.com/api/0ce1c4a981f7dd2a/geolookup/lang:AR/forecast/conditions/q/"+location+".json";
    fetch(dmJSON);
  }
  function fetch(dmJSON) {
    $.getJSON( dmJSON, function(parsed_json) {

      var html = '';
      html += '<div style="width: 600;direction: rtl;background-color: white;padding: 12px 12px 0;border: 1px solid;border-color: #e5e6e9 #dfe0e4 #d0d1d5;border-radius: 4px;margin-bottom: 20px;color: black;">';
      html += '<p>' + parsed_json.current_observation.weather  + ' </p>' ;
      html += '</div>';
      setInterval(function () {
        $(news).html(""); 
        fetch(dmJSON);
      }, 15000);
      $("#news").append(html);
    });
  }
});