Weather API - What im doing wrong?

Weather API - What im doing wrong?
0.0 0

#1

can someone help me and tell me what i might be doing wrong? console.log(lon); dont seem to be consoling the longitude from geolocation so i can get the lat and lon to create the weather API URL.
var lat = “”;
var lon = “”;
var url = “”;
var obj = {};

if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position){
lat = position.coords.latitude;
lon = position.coords.longitude;
url = “http://api.openweathermap.org/data/2.5/weather?lat=” + lat + “&lon=” + lon + “&appid=0fa32334aae58f9d4a6887841ba00e3e&units=metric”;
console.log(lon);

  $.ajax({
      type: "POST",
      url: url,
      contentType: "application/json",
      dataType: "jsonp",
      data: JSON.stringify(obj),
      success: function(response) {
        var weatherType = response.weather[0].description;
        var ico = response.weather[0].icon;
        var temp = response.main.temp;
        //console.log(weatherType);
        //console.log(temp)
        //console.log(response);

        // will need to do the following url based on icon code from JSON data "http://api.openweathermap.org/img/w/" + ico + ".png"
        //console.log(ico);
      },
      error: function(response) {
        console.log("error");
      }
    });


});

}


#2

It works at my location.I can get longitude as well as latitude.I guess it’s a browser/network issue.Or the typo ?

if (navigator.geolocation) {
	navigator.geolocation.getCurrentPosition(function(position){
	lat = position.coords.latitude; 
	lon = position.coords.longitude;
	url = "http://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&appid=0fa32334aae58f9d4a6887841ba00e3e&units=metric";
	console.log(lon);
        console.log(lat);

	}); // typo 
} // typo 


#3

are you using Chrome browser?


#4

yea i was testing it in chrome. from what i read i guess it dont work in chrome anymore. ive since found another way to do it with a different api to get the location then pass it to the url from openweathermap