Weather api need help

Can someone please tell me why I keep getting lat not defined?

$(document).ready(function() {
  //show location
  var data;
$.getJSON('https://ipinfo.io/geo', function(d){
        var lat = latitude;
        var lon = longitude;        
        var loc = lat,lon;
data=d.loc.split(",");

  
//console.log(response.ip, response.city, response.region);
    
console.log(data); 
    })
    })
    });

The latitude and longitude values you are trying to assign to var “lat” and var “lon” do not exist.
You stored the latitude and longitude in an array you called “data”. The array does not “know” that the first value in the array is a latitude and the second a longitude. You must access the values in the array with their index.

Have you tried following the link https://ipinfo.io/geo ? You will see exactly what properties the returned object has.

Your data=d.loc.split(","); is a good start. It created an array that looks like that :
["12.3456", "-12.3456"] . Now try to assign the value of the first item in the array (“12.3456”) to your latitude variable.

Try that first and come back if you still struggle with it!

thank you for your response!
I got it…

$(document).ready(function() {
//show location
var data;
$.getJSON(‘https://ipinfo.io/geo’, function(d){
var city = d.loc[0];
var region = d.loc[1];
var loc = [0,1];
data=d.loc.split(",");
$("#location").text(d.city + " , " + d.region);
console.log(data);

1 Like

Now I am getting a net::ERR_EMPTY_RESPONSE when I add the next section.
GET http://api.darksky.net/forecast/b0d3575b0f7a96bc1338523f79bbc2ab/40.8597,-74.4026callback=jQuery1112044735759682009135_1499026979985&_=1499026979986 net::ERR_EMPTY_RESPONSE

here is the code:
//get summary
$.ajax({
type:“GET”,
url:
http://api.darksky.net/forecast/b0d3575b0f7a96bc1338523f79bbc2ab
+"/"+loc,
dataType: “jsonp”,
success: function(data1) {

    var city = data1.city;
    var region = data1.region;
   var condition = data1.currently.summary; 



    $("#condition").text(data1.currently.summary);
    console.log(data1);

}