Uncaught ReferenceError: currentPosition is not defined

Hey guys, I’m working on the Local Weather Project and I’ve been stuck on this code for a couple days now. I keep getting this error. I only call getCurrentPosition in the script so I’m not sure why currentPosition is undefined.

Here is my JS:

$.get("https://ipinfo.io", function(response) {
    $("#location").html(response.city + ', ' + response.region);
}, "jsonp");
$(document).ready( function() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (callAPI) {
    
});
}
                                         
function callAPI(position) {
  var lat = "lat=:" + position.coords.latitude;
  var lon = "lon=:" + position.coords.longitude;
var weatherurl = "https://fcc-weather-api.glitch.me/api/current?" + lat  + '&'+ lon;
$.ajax ({
  url: weatherurl, success: function (data) {
  $('#desc').text(data.weather[0].main)
}
});
} 
 
});

Thanks in advance for the help!

1st your geolocation function should be like:

if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(callAPI);
}
1 Like

2nd You must also remove “:” in here var lat = "lat=:" + and in here var lon = "lon=:" +

Here an working example of your code

1 Like

Thank you . I made the changes and it worked!