sinjhan / php-google-map-api

Automatically exported from code.google.com/p/php-google-map-api
0 stars 0 forks source link

Implementing The Google Distance Matrix API #74

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Implementing The Google Distance Matrix API at 
https://developers.google.com/maps/documentation/distancematrix/

Original issue reported on code.google.com by crose...@gmail.com on 29 Apr 2012 at 3:19

GoogleCodeExporter commented 8 years ago

Original comment by b...@mycnl.com on 1 May 2012 at 9:44

GoogleCodeExporter commented 8 years ago
<?php
function curl_request($sURL,$sQueryString=null)
{
        $cURL=curl_init();
        curl_setopt($cURL,CURLOPT_URL,$sURL.'?'.$sQueryString);
        curl_setopt($cURL,CURLOPT_RETURNTRANSFER, TRUE);
        $cResponse=trim(curl_exec($cURL));
        curl_close($cURL);
        return $cResponse;
}

$sResponse=curl_request('http://maps.googleapis.com/maps/api/distancematrix/json
',
    'origins=04429&destinations=02135&mode=driving&units=imperial&sensor=false');
$oJSON=json_decode($sResponse);
if ($oJSON->status=='OK')
        $fDistanceInMiles=(float)preg_replace('/[^\d\.]/','',$oJSON->rows[0]->elements[0]->distance->text);
else
        $fDistanceInMiles=0;

echo 'Distance in Miles: '.$fDistanceInMiles.PHP_EOL;

Original comment by albrat...@gmail.com on 30 Sep 2014 at 4:58