Created
February 15, 2015 08:26
-
-
Save moradgholi/b7398063a791657df3e4 to your computer and use it in GitHub Desktop.
Google Direction API in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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