I\'m trying to get driving distance between two points using Google Maps API. Now, I have code which get direct distance:
This function get lat and
This is the method I got. In it, you can enter any manual distance from sessions or database.
$origin = urlencode($_SESSION['source1']);
$destination = urlencode($_SESSION['dest1']);
$url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=$origin&destinations=$destination&key=Your api key";
$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);
?>
Now the tough part was how to show distance. Well, with research, I got this answer:
You can print this result anywhere. It's working for me.