2017-12-01 11 views
0

저는 geolocation을 사용하는 날씨 앱을 만들고 있지만 검색도하고 있습니다.오픈 웨더 API에 대한 GET 요청이 작동하지 않습니다.

Geolocation 기능이 작동하지만 사용자 검색에 실패했습니다. 콘솔의 오류 : GET {api url} 404 (찾을 수 없음).

첫째, 작동하지 않는 기능 : 지금

function getWeatherWithUserInput() { 
    return new Promise(function(resolve, reject) { 

    var location = $("#location").val().trim(); 
    var widget = Mixcloud.PlayerWidget(document.getElementById('my-widget-iframe')); 

    var weatherCSQueryURL = "http://api.openweathermap.org/data/2.5/weather?q=" + location + "=&appid=" + WeatherAPIKey; 

    $.ajax({ 
     url: weatherCSQueryURL, 
     method: "GET" 
    }).done(function(response) { 
     //$(".city").html("<h1>" + response.name + " Weather </h1>"); 
     $(".wind").html("<h1>" + response.name + "</h1>"); 
     //$(".humidity").html("Humidity: " + response.main.humidity); 
     //var f_temp = 9/5*(response.main.temp-273)+32; 
     //$(".temp").html("Temperature (F) " + Math.floor(f_temp)); 
     resolve(response.weather[0].id); 
     }); 
    }); 
    }; 

작업을 수행하는 기능 : 나는 그 차이를 찾을 수 없습니다

function getWeatherWithGeo() { 
    return new Promise(function(resolve,reject) { 
    getGeoLocationGoogle() 
     .then(function(response) { 
      var lat = response.location.lat; 
      var lon = response.location.lng; 

      var weatherLLQueryURL = "http://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&appid=" + WeatherAPIKey; 
      $.ajax({ 
       url: weatherLLQueryURL, 
       method: "GET" 
      }).done(function(response) { 
       $(".wind").html("<h1>" + response.name + "</h1>"); 
       resolve(response.weather[0].id); 
      }); 
     }) 
     }) 

    } 

, 왜 하나가 동안 작동합니다 다른 사람은 그렇지 않습니다. 어떤 제안을 환영합니다!

+0

어쩌면 위도 및 로그와 관련된 오류입니까? 또한 js 내에서 사용 가능한 메소드에서 위도 및 로그를 작성하는 것이 좋습니다. –

+0

@FlorianSchaal 오류가 "GET {여기에있는 URL이 404} (찾을 수 없음)"입니다. –

+0

@DeepakJha 두 번째 함수 (위도 및 로그를 사용하는 두 번째 함수)가 제대로 작동하지만 첫 번째 함수는 작동하지 않습니다. . Get 요청에 대해 404를 제공합니다. –

답변

1

올바른 URL이 있어야한다 :

var weatherCSQueryURL = "http://api.openweathermap.org/data/2.5/weather?q=" + location + "&appid=" + WeatherAPIKey; 

위치가 다른 값을 요구하고 위치가 PARM 것 아약스 요청을 이야기 한 후 = 기호.

+0

예, 감사합니다. 2 분 안에 답을 받아 들일거야. –

+0

@ 닉 탐불로 오신 것을 환영합니다. –