I am using Google Distance Matrix Service to calculate driving distances between claimant location(stored in gClaimantLatLng) and value stored in gBookingsProfileArray[i].CompanyLatLng but when everything executes I sometimes get no values in gDistanceProfileArray or sometimes I get values in the wrong order. I am calculating distance of approx. 40 locations.

Code:
function GetCriteria_Profile()
{
    LoadDistanceArray_Profile();    
    GetCriteria_Availability();                         
}   

function DistanceArray_Profile_Callback(response, status)
{
    if (status != google.maps.DistanceMatrixStatus.OK)  
        alert('Error was: ' + status);  
    else 
        gDistanceProfileArray.push(response.rows[0].elements[0].distance.text);                 
}

function LoadDistanceArray_Profile()
{       
    gDistanceProfileArray = []; 

    if(gBookingsProfileArray.length > 0)
    {       
        for(var i= 0; i < gBookingsProfileArray.length; i++)
        {                   
            var CurrentDistanceLatLng = gBookingsProfileArray[i].CompanyLatLng;                     

            if(CurrentDistanceLatLng != '') 
            {                           
              var service = new google.maps.DistanceMatrixService();
              service.getDistanceMatrix(
                {
                  origins: [gClaimantLatLng],
                  destinations: [CurrentDistanceLatLng],
                  travelMode: google.maps.TravelMode.DRIVING,
                  unitSystem: google.maps.UnitSystem.METRIC,
                  avoidHighways: false,
                  avoidTolls: false
                }, DistanceArray_Profile_Callback);                     
            }
            else
                gDistanceProfileArray.push('');                         
        }       
    }       
}