I am creating a weather app using jquery. The issue that I am having is in my getJSON I would like to use a variable that I have created using your current latitude and longitude coordinates. The url with my openweather api key loads the json file just fine in the browser but it does not seem to want to work in my getJSON.
Here is my javascript code to display the weather information based off your location.
var lat;
var lon;
var jsonURL;
navigator.geolocation.getCurrentPosition(GetLocation);
function GetLocation(location) {
lat = location.coords.latitude;
lon = location.coords.longitude;
jsonURL = 'api.openweathermap.org/data/2.5/weather?lat=' + lat + '&lon=' + lon + '&APPID=example&units=imperial'
}
$("#getWeather").click(function(){
console.log(jsonURL);
$.getJSON(jsonURL , function( data ) {
var items = [];
items = data; $("#weather").text(items.main.temp).append('℉');
});
});
APPID.