I have a serious problem in JS on creating a weather machine

My project link is here -> https://codepen.io/CreatorInCloud/pen/BmrbKM.
I want to add the lat and lon in the url but my question is how can i add a everchanging latitude and longitude in a Double quoted url. Kindly Go to the link for more info. Thank you.

You’ll have to call .getJSON inside the callback for the geolocation. You can then use plain string concatenation (or ES6 template literals) to construct a URL with the location information in it.

if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(function(position) {
    var latitude = position.coords.latitude;
    var longitude = position.coords.longitude;

    $.getJSON(
      "https://fcc-weather-api.glitch.me/api/current?lat=" + latitude + "&lon=" + longitude,
      function(json) {
        $("#data").html(JSON.stringify(json));
      }
    );
  });
}
1 Like

@kevcomedia Thank you buddy. It worked.