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

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

#1

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.


#2

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));
      }
    );
  });
}

#3

@kevcomedia Thank you buddy. It worked.