Hi,

As part of a project i am developing a taxi booking system. A part of it i am struggling to even think of what to do for is knowing distances between two real addresses e.g. Birmingham and Manchester for reasons such as calculating prices. Obviously it would be impractible to even think of storing all distances in my database between every combination of two locations.

Is there a known method of doing this sort of procedure?

Could google maps or something similar be incorporated to calculate distances? If so, how?

Any help would be much appreciated as i have no clue in this area whatsoever.
Thanks.

Anyone even have an idea?

Thanks, that looks promising! Just gotta find out how to use it.

<?php
function distance($origin,$destination) {


// replace any spaces in origin and destination with +
$originexplode = explode(" ", $origin);
$destinationexplode = explode(" ", $destination);
$orgincount = count($originexplode);
$destinationcount = count($destinationexplode);
 
 $origin  = str_replace(" ", "+", $origin);
 $destination  = str_replace(" ", "+", $destination);

// send http request to gooldle
  $url = "http://maps.googleapis.com/maps/api/distancematrix/xml?origins=$origin&destinations=$destination&mode=driving&units=imperial&sensor=false";
  
// get data back from google
 $data = @file_get_contents($url);

// break the data down and get what we need and set the right spots for data and return data
$data1 = explode(" ", $data);

// set where the data is located if only two words are there
$one = 28;
$two = 27;
$three = 42;;
$four = 43;

// set where the data is located if the address gets bigger
if($orgincount > 2){
$one = 28 + $orgincount;
$two = $one + 1;
$three = 42 + $orgincount;
$four = $three + 1;
}

// set where the data is located if the address gets bigger
if($destination > 2){
$one = (28  + $destinationcount) + 1 ;
$two = $one + 1;
$three = (42 + $destinationcount) + 2;
$four = $three + 1;
}



$returndata = $data1[$one]." ".$data1[$two]." ".$data1[$three]." ".$data1[$four];

return $returndata;
}




  $getinfo = distance("lindenhurst ny"," farmingdale ny");
  
  echo $getinfo;
?>

Much appreciated! Just had a quick read and have grasped sort of what it is doing. Haven't got much time at the moment so i will read through it in more detail later on.

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.