I am trying to create a function that executes two async actions simultaneously. One is a simple AJAX request, and the second is for getDistanceMatrix from the google maps API. The point is that I want to have a single callback function that uses the data from both of the functions. I am familiar with the JQUERY function $.when(), but I could only use It when dealing with two AJAX functions, but not with the google API. This is the code that I am trying to get to work. a1 is fine, but a2 is undefined.

```
function getLocation(){
    var service = new google.maps.DistanceMatrixService()
    var origin = new google.maps.LatLng(32.07989,34.813026);
    var destination = new google.maps.LatLng(32.08989,34.813026);
    return  service.getDistanceMatrix({
        origins: [origin],
        destinations: [destination],
        travelMode: google.maps.TravelMode.WALKING ,
        unitSystem: google.maps.UnitSystem.METRIC,
        avoidHighways: false,
        avoidTolls: false
    })
}
function getFriends(){
    return $.ajax({
        data: "&action=get_friends"
    });
$.when( getLocation(),getFriends()).done(function(a2,a1){
        alert(a1)
        alert(a2)
    });
}

```

My guess is that google maps API just don't return any value, but I would like to find a solution that doesn't involve complicated patterns.  

Thanks for your time,  

Daniel