Given below the code for it.
//intiat curl
$ch = curl_init();
//pass the both start and end lat & long
//check google map doc for option
//mode=driving is for driving distance
//sensor=false for site ,for mobile then it is true
//reponse is json
curl_setopt($ch, CURLOPT_URL,
"http://maps.google.com/maps/api/directions/json?origin=".trim($latitude).",".trim($longitude)."&destination=".$obj->latitude.",".$obj->longitude."&mode=driving&alternatives=false&units=imperial&sensor=false");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec ($ch);
$contents=json_decode($contents);
$distance=$contents->routes[0]->legs[0]->distance->text
No comments:
Post a Comment