I have made an API call with the help of $.getJSON but I don't know how do I make the returned data available globally to be used in other functions as well.
The return in below code doesn't work but instead if I alert it: it works charms.
$.getJSON(url, function(timeInfo){
return timeInfo.time;
});
Also out of 2010-12-09 12:53 time format. How do I take the 12 (the hour) out.
Please help and sorry for including two questions in one.
Detailed code:
function handle_geolocation_query(position) {
if(position[0] == 'Yes'){
var url = "http://ws.geonames.org/findNearByWeatherJSON?lat=" + position[1] + "&lng=" + position[2] + "&callback=?";
} else {
var url = "http://ws.geonames.org/findNearByWeatherJSON?lat=" + position.coords.latitude + "&lng=" + position.coords.longitude + "&callback=?";
}
$.getJSON(url, function(weatherInfo){
var clouds = weatherInfo.weatherObservation.clouds;
var weather = weatherInfo.weatherObservation.weatherCondition;
var time = getTimeInfo(position);
if(time.getHours()>=6 && time.getHours()<=18){
var weatherClass = placeImageDay(clouds, weather);
$('#weatherImage').show().addClass(weatherClass);
} else {
var weatherClass = placeImageNight(clouds, weather);
$('#weatherImage').show().addClass(weatherClass);
}
});
}
function getTimeInfo(position){
if(position[0] == 'Yes'){
var url = "http://ws.geonames.org/timezoneJSON?lat=" + position[1] + "&lng=" + position[2] + "&callback=?";
} else {
var url = "http://ws.geonames.org/timezoneJSON?lat=" + position.coords.latitude + "&lng=" + position.coords.longitude + "&callback=?";
}
$.getJSON(url, function(timeInfo){
return timeInfo.time;
});
}