Show the Local Weather API request problem


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 = "";
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
//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
if (tempUnit == “Celsius”) {
tempUnit = “Fahrreneinheit”;
}else {
tempUnit = “Celsius”;

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

//make the API request
$.getJSON(url, function(data){

Thanks for help :smiley:


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


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