OK, here is a fuller version of what you need: <?php function getDistance($addressFrom, $addressTo, $unit){ //Change address format $formattedAddrFrom = str_replace(‘ ‘,’+’,$addressFrom); $formattedAddrTo = str_replace(‘ ‘,’+’,$addressTo); //Send request and receive json data $geocodeFrom = file_get_contents(‘http://maps.google.com/maps/api/geocode/json? address=”.$formattedAddrFrom.”&sensor=false’); $outputFrom = json_decode($geocodeFrom); $geocodeTo = file_get_contents(‘http://maps.google.com/maps/api/geocode/json? address=”.$formattedAddrTo.”&sensor=false’); $outputTo = json_decode($geocodeTo); //Get latitude and longitude from geo data $latitudeFrom = … Read more