Quantcast
Channel: Webkul Blog
Viewing all articles
Browse latest Browse all 5553

PHP get distance between two places using google maps

$
0
0
Use curl to use google map api to get the distance.
Here the format of address
$address = $value["street"]." ".$value["region"]." ".$value["country_id"]." ".$value["zip_code"];

Now just paste the code

$url = "http://maps.googleapis.com/maps/api/directions/json?origin=".str_replace(' ', '+', $source_address)."&destination=".str_replace(' ', '+', $destination_address)."&sensor=false";
	            $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_all = json_decode($response);
	            // print_r($response);
	            $distance = $response_all->routes[0]->legs[0]->distance->text;

Get $distance and use
:)


Viewing all articles
Browse latest Browse all 5553

Trending Articles