1. Go to this page and download the library: Download alexpechkarev/google-maps library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$routeParams = [
'origin' => [ /* ... origin details ... */ ],
'destination' => [ /* ... destination details ... */ ],
'travelMode' => 'DRIVE',
// ... other Routes API parameters ...
];
$responseArray = \GoogleMaps::load('routes') // Use 'routes' service
->setParam($routeParams)
->setFieldMask('routes.duration,routes.distanceMeters,routes.polyline.encodedPolyline') // optional - used to specify fields to return
->fetch(); // Use fetch() for Routes API
// $responseArray is already a PHP array
if (!empty($responseArray['routes'])) {
// Process the route data
} else {
// Handle errors or no routes found
}
$matrixParams = [
'origins' => [ /* ... array of origins ... */ ],
'destinations' => [ /* ... array of destinations ... */ ],
'travelMode' => 'DRIVE',
// ... other Route Matrix parameters ...
];
$responseArray = \GoogleMaps::load('routematrix') // Use 'routematrix' service
->setParam($matrixParams)
->setFieldMask('originIndex,destinationIndex,duration,distanceMeters,status,condition') // optional - used to specify fields to return
->fetch(); // Use fetch() for Routes API
// $responseArray is already a PHP array
// Process the matrix data