Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    Feb 2009
    Posts
    121
    Thanks
    7
    Thanked 0 Times in 0 Posts

    gDistanceProfileArray is either empty or result in the wrong order when using Google

    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('');							
    		}		
    	}		
    }
    Last edited by asifakhtar; 04-16-2014 at 01:04 AM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •