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

One thought on “google map with calculate between more than two places in php

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s