Get longitude and latitude values ββfrom google webserivce and pass values ββto open api weather map to get temperature values. Code below
function getWeatherData(latitude, longitude) { var temperature = 0; var url = "http://api.openweathermap.org/data/2.5/weather?lat="; url = url + latitude; url = url + "&lon="; url = url + longitude; url = url + "&cnt=1"; $ .ajax({ type : "POST", dataType : "jsonp", url : url + "&callback=?", async : false, success : function(data) { temperature = data.list[0].main.temp ; alert (temperature); }, error : function(errorData) { alert("Error while getting weather data :: "+errorData.status); } }); return temperature;
So for this URL
http://api.openweathermap.org/data/2.1/find/city?lat=22.572646&lon=88.36389500000001&cnt=1
We get the JSON response below in the browser
{ "message": 0.016, "cod": "200", "calctime": "", "cnt": 1, "list": [{ "id": 1275004, "name": "Kolkata", "coord": { "lon": 88.36972, "lat": 22.569719 }, "distance": 0.999, "main": { "temp": 301.15, "pressure": 998, "humidity": 88, "temp_min": 301.15, "temp_max": 301.15 }, "dt": 1371217800, "wind": { "speed": 3.1, "deg": 150 }, "clouds": { "all": 40 }, "weather": [{ "id": 721, "main": "Haze", "description": "haze", "icon": "50n" }] }] }
But when trying to get the same using jQuery ajax, I have no option but to get values ββas JSONP, cannot get it as JSON
Since I cannot get a JSON response, I cannot make an asynchronous call.
I need to make asynchronous false. Because of this, each time the temperature of the value is set to 0 and I can not get the actual temperature value that I get from the ajax call
Please, help