Categories

Saturday, December 21, 2024
#919814419350 therichposts@gmail.com
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

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

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

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