Google Map ApiPhp

How to Calculate distance and duration between two geo locations Using PhP Curl?

Calculate distance and duration between two geo locations Using PhP Curl

Views

Hello, welcome to therichpost.com. In this post, I will tell you,  How to Calculate distance and duration between two geo locations Using PhP Curl? I personally like php ver much. PHP is the best web language. There are many cms and frameworks in PHP and WordPress is the best example. facebook also used PHPin it.

Today we will Calculate distance and duration between two geo locations Using PhP Curl.

php-curl-geo-location

 I am calculating distance between Ludhiana and Delhi.

Here is the working code  and you have to enable curl on your system if it will not work:
<?php
$url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=30.900965,75.857276&destinations=28.704059,77.102490&mode=driving&language=en";
$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);

//print_r($response_a);

$status = $response_a['rows'][0]['elements'][0]['status'];

if($status == 'OK') {
echo "Total Distance : ".$response_a['rows'][0]['elements'][0]['distance']['text'] ."<br> Total Time : ".$response_a['rows'][0]['elements'][0]['duration']['text'];
}
?>

 There are so many code in PHP and i will let you know all. Please do comment if you   any query related to this post. Thank you. Therichpost.com

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Positive SSL