We help IT Professionals succeed at work.
Get Started

PHP Distance Between 2 Addresses - Part 2

beeman000 asked
Last Modified: 2012-08-13
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.
		<script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;sensor=false&amp;key=ABQIAAAA7krqpTmmfiYdkJ0N9Z2iHRQ54BZ5lbd6D3Bd5hI6QK4whcZT8hR98K0EfSgTxgyO9u8EA0uPSlcAkA"
    <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;
		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

Watch Question
Most Valuable Expert 2011
Author of the Year 2014
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE