How to find out driving distance in two location

made for opencart.

 

public function distanceFinder() {
if (isset($this->request->get[‘zip’])) {
$customerZipCode = (int)$this->request->get[‘zip’];
} else {
$customerZipCode = 0;
}

$postcode1=urlencode(‘12139 sweden’);
$postcode2=urlencode(“$customerZipCode sweden”);
$url = “http://maps.googleapis.com/maps/api/distancematrix/json?origins=$postcode2&destinations=$postcode1&mode=driving&language=en-EN&sensor=false”;

$data = file_get_contents($url);
$result = json_decode($data, true);

foreach($result[‘rows’] as $distance) {
if($distance[‘elements’][0][‘duration’][‘text’]>20) {
echo “not deliverable”;
}
else
{
print “deliverable”;
}

}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

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