Using $.getJSON

Using $.getJSON
0.0 0


I’m having some trouble using the getJSON() function in order to retrieve weather information for the weather application.

    $(document).ready(function() {
      $("#getWeather").click(function() {
       if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(function(position) {
        var lat = position.coords.latitude;
        var lon = position.coords.longitude;
        var url_api = ""+lat+","+lon;
        $.getJSON(url_api, function(json) {
          $("ul").html("<li>latitude: " + json.latitude + "</li>");
          $("ul").html("<li>longitude: " + json.longitude + "</li>");

I’m trying to approach the problem piece-by-piece by just getting my application to show me the latitude and longitude before I proceed with getting the temperature, and weather.



I am not getting into the navigator.geolocation api because I solved it another way. Which is the following and it might help you hopefully.

First get your lon and lat vars which you than paste into the url of your getJSON for darksky.


    $.getJSON("", function(data) {

    // declare lon, lat.

    // inside this function $.getJSON for darksky since the vars need to be available.

    } );

Instead of printing something on the page as a list item just use console.log and debug in the inspector, you wanted to break it down piece by piece. Thats where console.log comes in handy. Good luck! ~Hope this helps…