Skip to content

Instantly share code, notes, and snippets.

@moradgholi
Created February 15, 2015 08:26
Show Gist options
  • Select an option

  • Save moradgholi/b7398063a791657df3e4 to your computer and use it in GitHub Desktop.

Select an option

Save moradgholi/b7398063a791657df3e4 to your computer and use it in GitHub Desktop.
Google Direction API in PHP
function getGoogleDirection($origin, $destination, $addDecodedPolyline = false){
$googleRoutingURL = "http://maps.googleapis.com/maps/api/directions/json?";
$data = [
'origin' => $origin,
'destination' => $destination,
'language' => 'fa',
'alternatives' => 'true'
];
$json = file_get_contents($googleRoutingURL . http_build_query($data));
$json = json_decode($json,1);
if($json['status'] == "INVALID_REQUEST" ||
$json['status'] == "OVER_QUERY_LIMIT" ||
$json['status'] == "REQUEST_DENIED" ||
$json['status'] == "UNKNOWN_ERROR" ){
Log::critical("Routing Result problem", ["REQUEST" => $data, "RESPONSE" => $json]);
}
foreach ($json['routes'] as $route){
// do whaterver
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment