I know that "but it works on my computer" is one of the things I should never say, but here we are.
I have a little app that gets your location, gets your weather, then gives you a music playlist.
Using the files locally, you can use geolocation OR search any location by name.
On my deployed S3 version, searching for any location just brings up your geolocation results. So the input and search form isn't working.
Here's the code:
Input Location:
$("#input-location").click(function(event){
event.preventDefault();
$('#mix-display').show();
$('#skipButton').show();
getWeatherWithUserInput()
.then(function(response) {
weatherCode = response;
showMix(weatherCode);
})
});
Get location with geolocation:
$('#get-location').click(function(event){
event.preventDefault();
$('#mix-display').show();
$('#skipButton').show();
getWeatherWithGeo()
.then(function(response) {
weatherCode = response;
showMix(weatherCode);
})
});
Here are the two weather functions (I understand that there's lots of dumb code-repetition going on here, I will eventually fix this!):
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("<h2>" + response.name + ": </h2>");
var f_temp = 9/5*(response.main.temp-273)+32;
$(".temp").html("<h2>" + Math.floor(f_temp) + "℉</h2>");
resolve(response.weather[0].id);
});
})
})
}
Get weather from input:
function getWeatherWithUserInput() {
return new Promise(function(resolve, reject) {
var location = $("#location").val().trim();
var weatherCSQueryURL = "http://api.openweathermap.org/data/2.5/weather?q=" + location + "&appid=" + WeatherAPIKey;
$.ajax({
url: weatherCSQueryURL,
method: "GET"
}).done(function(response) {
$(".wind").html("<h2>" + response.name + ": </h2>");
var f_temp = 9/5*(response.main.temp-273)+32;
$(".temp").html("<h2>" + Math.floor(f_temp) + "℉</h2>");
resolve(response.weather[0].id);
});
});
};
full code is here: https://github.com/nicktamburro/YouAreListeningToWeather
deployed version here: http://www.youarelisteningtoweather.com