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"

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.