1

I would like the function timeZoneFix to return the variable timeFromLocation. The data is stuck in timeZoneAPI(...){...}. I want to get it out to be able to use it. I couldn't figure it out how to do this thanks!

function timeZoneFix(lat,lng,time){
    var locationInfo=[lat,lng,timeStamp/1000];
    timeZoneAPI(locationInfo,function(result){
    var timeFromLocation=[result.dstOffset,result.rawOffset];
    });
}

var timeZoneAPI = function(locationInfo,callback) {
  xhr = Titanium.Network.createHTTPClient();
  var url = buildUrl(locationInfo);
  xhr.open('GET', url);
  xhr.onload = function() {
    var result = JSON.parse(this.responseText);
    callback(result);
  };
  xhr.send();
};
dertkw
  • 7,798
  • 5
  • 37
  • 45
PainAndGain
  • 137
  • 1
  • 1
  • 12
  • The same way you do it with `timeZoneAPI`: You accept/pass a callback. – Felix Kling Jun 29 '14 at 18:16
  • Thanks but I don't know how to do it. I am still trying but even with a callback I got "null"... – PainAndGain Jun 29 '14 at 18:25
  • You do it exactly the same as with `timeZoneAPI`: Make `timeZoneFix` accept a callback. Inside `timeZoneFix`, call `callback(timeFromLocation);`, and call `timeZoneFix` as `timeZoneFix(lat, lng, time, function(result) { /* do something with the result */ });`. *Returning* the result from `timeZoneFix` is not possible. – Felix Kling Jun 29 '14 at 18:29
  • So it is not possible to return a result from timeZoneFix! Thanks – PainAndGain Jun 29 '14 at 19:06

0 Answers0