Google Maps API to calculate location distance in PHP
This example shows how to use the Google maps API to calculate distance between two places in PHP
$result = file_get_contents('http://maps.googleapis.com/maps/api/directions/json?origin=Chicago,IL&destination=Raleigh,NC&sensor=false'); $result = json_decode($results); $distance = $result->routes->legs->distance['text']; echo $distance // Outputs: "xxx mi"
Making REST requests from PHP
The most simplest way is to use
$data = json_decode( file_get_contents(“http://www.w3mentor.com/service.json”) );
This example won’t work on servers that explicitly disable the URL opening behavior, mostly seen in shared hosting environment.
