Tag Archives: google

google map with calculate between more than two places in php

<?php
$travel_location = ‘1st main Road&Peenya Industrial Area’;

$bootloca = explode(‘&’,$travel_location);
$origins = str_replace(‘ ‘, ‘+’, $_REQUEST[‘city’]);
$destinations = ”;
foreach($bootloca as $book):
$destinations = $destinations.str_replace(‘ ‘, ‘+’, $book).’|’;

endforeach;

$json=file_get_contents(“http://maps.googleapis.com/maps/api/distancematrix/json?origins=&#8221;.$origins.”&destinations=”.$destinations.”&mode=driving&sensor=false”);

$json=json_decode($json,true);
//print ‘<pre>’;
//print_r($json);   // for check array value
//print ‘</pre>’;
$total_distance = 0;
foreach($json[“rows”][0][“elements”] as $dist):

$total_distance += ceil($dist[“distance”][“text”]);

endforeach;

print $total_distance;
?>

Advertisements