Link to home
Start Free TrialLog in
Avatar of beeman000
beeman000

asked on

PHP Distance Between 2 Addresses - Part 2

Here is the PHP Code:

I am getting a javascript error in IE, but not firefox. This code is enclosed in a loop that for which there is a javascript error the first 2 iterations but not the third. On the third the Google Mapping call works perfectly.
echo'
		<script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;sensor=false&amp;key=ABQIAAAA7krqpTmmfiYdkJ0N9Z2iHRQ54BZ5lbd6D3Bd5hI6QK4whcZT8hR98K0EfSgTxgyO9u8EA0uPSlcAkA"
            type="text/javascript"></script>
    <script type="text/javascript">
        <!--
 
        function getDistance(pointA, pointB){
                // For this example I\'ll assume pointA and pointB are freeform addresses.
                var directions = "from: "+pointA+" to: "+pointB;
 
                // Initialize the GDirections class, load the directions
                gd = new GDirections(null,null);
 
                loader = gd.load(directions, {"locale" : "en_US"});
 
                // event listener
                GEvent.addListener(gd, "load", onLoader);
 
 
        }
 
        function onLoader(){
 
                // Grab the distance between point A and point B
                var distance = gd.getDistance().meters;
					 distance = distance/1600;
                distance = roundNumber(distance, 1);
                var duration = gd.getDuration().html;
               
 
                
					 // Alert the distance string
                document.getElementById(\'row'.$rowNumber.'\').innerHTML = distance;
        			 
		  }
        -->
        </script>
		';
		echo '<script type="text/javascript">getDistance(\''.$customerAddress.'\', \''.$cleanerAddress.'\');</script>';
		echo '<td style="border-top:solid;border-top-color:#CCCCCC;">';
		echo '<div id="row'.$rowNumber.'"></div>';
		echo '</td>';
		$rowNumber = $rowNumber+1;
	}

Open in new window

Avatar of beeman000
beeman000

ASKER

To reiterate: the javascript error I am getting is:
gd.getDistance().meters is null or not an object
Have you got Firebug installed with Firefox?  Try that and see if you can see more about the error there.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial