Show the Local Weather API request problem


#1

Hello, I have a problem with my API request for the Weather Application. When I try to make the API request I get following Error message:

  • {“error”:“Please provide longitude as lon and latitude as lat as numbers/floats.”}

I understand that my problem lies at the number format of my latitude and longitude numbers, but how can i convert them to fit it in my code ?

here is my code:

// Global variables to use
var url = "https://fcc-weather-api.glitch.me/api/current?";
var lat;
var long;
var buttonFahrText = "Change the temperature unit to Fahrreneinheit"
var buttonCelText = "Change the temperature unit to Celsius"
var tempUnit = “Celsius”

//function to work when website has loaded
$(document).ready(function(){
//if else satement to get location
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
latitude = position.coords.latitude;
longitude = position.coords.longitude
getWeather(latitude, longitude);
});
}else {
console.log(“The current location is not avalaible”);
}

//function to get the state of the button
$("#tempUnitButton").click(function(){
if (tempUnit == “Celsius”) {
tempUnit = “Fahrreneinheit”;
$("#tempUnitButton").text(buttonCelText);
}else {
tempUnit = “Celsius”;
$("#tempUnitButton").text(buttonFahrText);
}
})
});

// /x/implement the Wetaher API request
function getWeather(lat, long) {
//build the website url
lat = “lat=” + lat;
long =“lat=” + long;
url = url+lat+long;
console.log(url);

//make the API request
$.getJSON(url, function(data){
console.log(data);
})
}
//

Thanks for help :smiley:


#2

long = "lat=" + long => You forgot to change “lat” to “lon”.
url = url+lat+long => You need an & in between different parameters


#3

Thanks man!
There are always tiny things you don’t see in the first moment when you search for the problem cause :smiley: