PHP code example of davit37 / php-google-maps-distance-matrix

1. Go to this page and download the library: Download davit37/php-google-maps-distance-matrix 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/ */

    

davit37 / php-google-maps-distance-matrix example snippets




'providers' => [
    ...
    \TeamPickr\DistanceMatrix\Frameworks\Laravel\DistanceMatrixServiceProvider::class,
]



'aliases' => [
    ...
    'DistanceMatrix' => \TeamPickr\DistanceMatrix\Frameworks\Laravel\DistanceMatrix::class,
]

$license = new StandardLicense($apiKey);

$license = new PremiumLicense($clientId, $encryptionKey);

$request = new DistanceMatrix($license);

// or

$request = DistanceMatrix::license($license);

$response = DistanceMatrix::license($license)
    ->addOrigin('norwich,gb')
    ->addDestination('52.603669, 1.223785')
    ->request();
   
// I want to make the following but of API better,
// as it looks horrible at the moment.
$rows = $response->rows();
$elements = $rows[0]->elements();
$element = $element[0];

$distance = $element->distance();
$distanceText = $element->distanceText();
$duration = $element->duration();
$durationText = $element->durationText();
$durationInTraffic = $element->durationInTraffic();
$durationInTrafficText = $element->durationInTrafficText();

// or

$response->json['destination_addresses'][0];
$response->json['rows'][0]['elements'][0]['distance']['value'];
$response->json['rows'][0]['elements'][0]['duration_in_traffic']['text'];

"davit37/php-google-maps-distance-matrix": "^1.2",


$ php artisan vendor:publish --tag=config