私はジオロケーションを使用する天気アプリを作成していますが、検索も行っています。オープンウェザー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が働くだろう、なぜ私は、違いを見つけるように見えることはできません他はしません。どんな提案も歓迎!
latとlogには何らかのエラーがありますか?また、js内の利用可能なメソッドからlatとlogを作成することをお勧めします。 –
@FlorianSchaalエラーは "GET {ここにあるurlは404}"(見つからない) " –
@DeepakJha 2番目の関数(latとlogを使う関数)はうまくいきます。 。これはGetリクエストに対して404を与えます。 –