asendjasni
asendjasni

Reputation: 1074

couldn't get the data from the openWeatherMap api JavaScript

don't know where the problem is but nothing was displayed in the div selected .

    $(document).ready(function(){
  var lat, lng, data;

  // get the current location
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function(position) {
          lat = position.coords.latitude;
          lng = position.coords.longitude;
        });
    }else {
      alert('Geo Location feature is not supported in this browser.');
   }


//get the data from the openWeatherMap API
  function getData(){
    $.getJSON('api.openweathermap.org/data/2.5/weather?lat='+lat+'&lon='+lng+'', function(json){
      data = json;
    });    
  }
  $('button').on('click', function(){
    getData();
    $(this).remove();
    $('.container').removeClass('hidden');
    $('#location').appendTo(data.name);
    $('#Weather-condition').appendTo(data.weather.main); 
    $('#wind-speed').appendTo(data.wind);
  });

});

Upvotes: 1

Views: 150

Answers (2)

Broven
Broven

Reputation: 63

you can find this problem from two side

  • are you get data from ajax? PS:you can add c.log(data)
  • are you success show data in your web Page

Upvotes: 1

csabinho
csabinho

Reputation: 1609

It looks like you've got a typo: getJESON instead of getJSON!

Upvotes: 2

Related Questions