distance in km between two points in php using curl

<?php
$origin="indore";
$destination="delhi";
//$origin = urlencode($_SESSION['source1']);
//$destination = urlencode($_SESSION['dest1']);

$url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=$origin&destinations=$destination&key=AIzaSyCBK8biD4eeBl4E1GoRdh57ndMTHWfYQX4";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
$response_a = json_decode($response, true);
?>

<div class="">
  <?php echo $response_a['rows'][0]['elements'][0]['distance']['text']; ?>

</div>

Comments

Popular posts from this blog

dynamic create multiple ckeditor onclick event using jquery

get lat and long from city name using jquery

membership registration and login system in php