Weather project error message: "{'error':'Please provide longitude as lon and latitude as lat as numbers/floats.'}"

Weather project error message: "{'error':'Please provide longitude as lon and latitude as lat as numbers/floats.'}"
0

#1
// global variables
var base_url = "https://fcc-weather-api.glitch.me/api/current?";
var lat = '' ;
var lon = '' ;

//window.addEventListener('load', getLocation);

//<iframe src="https://codepen.io/" allow="geolocation"></iframe>

$(document).ready(function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(success);
  } else {
    var para = document.createElement('p');
  para.textContent = "Geolocation is not supported by your browser";
  document.body.appendChild(para);
  };
  });

    function success(position) {
    lat = position.coords.latitude;
    lon = position.coords.longitude;
    }

      
var url = base_url + lat + '&' + lon ;

var weatherRequest = new XMLHttpRequest(); 
 //might need to add actual URL 
weatherRequest.open('GET', url);

      weatherRequest.onload = function() {
  //console.log(weatherRequest.responseText);
};

console.log(url);

#2

Ok, so figured out the problem specifically lies with the url i’m using. When I load the end point, it loads to the console no problem. So i’d like to understand how I can get my “var url” variable to load and pass coordinates so I can get a proper response. Additionally, when I check the chrome console I get the following errors:

“pen.js:12 [Deprecation] getCurrentPosition and watchPosition usage in cross-origin iframes is deprecated and will be disabled in M63, around December 2017. To continue to use this feature, it must be enabled by the embedding document using Feature Policy, e.g. <iframe allow=“geolocation” …>. See https://goo.gl/EuHzyv for more details.”

but when I use the iframe code, I get the following error:
“Unexpected token <”


#3

Your URL will look like: https://fcc-weather-api.glitch.me/api/current?SomeNumber&SomeNumber

But it shoud look like:
https://fcc-weather-api.glitch.me/api/current?lat=SomeNumber&lon=SomeNumber

Have a look here: https://fcc-weather-api.glitch.me


#4

Thank you! Super helpful.