API Trouble - Can't get api to accept coords

Hey everybody,

I’m trying to build my weather app and can’t seem to get my API to work properly. The key is correct and I have a valid account with them so that’s not the issue. I even have the .getCurrentPosition function properly but I don’t know how to get the API URL to accept or determine the coordinates for it to do its thing?

if (navigator.geolocation) {

  navigator.geolocation.getCurrentPosition(function(position) {
    var lat = position.coords.latitude;
    var lon = position.coords.longitude;
    var api = "api.openweathermap.org/data/2.5/weather?lat="+lat+"&lon="+lon+"&appid=*******mykey*******";
    $("#location").html("latitude: " + lat + "<br>longitude: " + lon);    

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


Since you are using jQuery syntax in your project already, take a look at the jQuery $.ajax method which will allow you to make a request to the API specified in your api url string.