2017-12-01 14 views
0

私はジオロケーションを使用する天気アプリを作成していますが、検索も行っています。オープンウェザーAPIのGETリクエストが機能しない

ジオロケーションの機能は動作していますが、ユーザーの検索は失敗しています。コンソールのエラーは、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); 
      }); 
     }) 
     }) 

    } 

ながら1が働くだろう、なぜ私は、違いを見つけるように見えることはできません他はしません。どんな提案も歓迎!

+0

latとlogには何らかのエラーがありますか?また、js内の利用可能なメソッドからlatとlogを作成することをお勧めします。 –

+0

@FlorianSchaalエラーは "GET {ここにあるurlは404}"(見つからない) " –

+0

@DeepakJha 2番目の関数(latとlogを使う関数)はうまくいきます。 。これはGetリクエストに対して404を与えます。 –

答えて

1

正しいURLは次のようになります。

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

=記号場所は別の値を求めると場所はPARMだろうAJAXリクエストを言っていた後。

+0

はい、完璧です、ありがとうございます!彼らは2分であなたの答えを受け入れるようにします。 –

+0

@NickTamburroようこそ –

関連する問題