function test(){
var distance=null;
first();
second();
third();
alert(distance);//it shows null always because it take 2 second to complete.
}
fun
Make use of callbacks:
function first(tolat, tolon, fromlat, fromlon, callback) {
if (typeof(callback) == 'function') {
callback(distance);
}
}
function second() { }
function third() { }
first("vartolat", "vartolon", "varfromlat", "varfromlon", function(distance) {
alert(distance);
second();
third();
});