PHP code example of codingphase / google-distance

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

    

codingphase / google-distance example snippets



$distanceMatrix = new GoogleDistanceMatrix('YOUR API KEY');
$distance = $distanceMatrix
    ->setLanguage('nl-NL')
    ->addOrigin('51.458428,6.0541768')
    ->addDestination('48.139212,11.581721')
    ->addDestination('36.721184,-4.420084')
    ->sendRequest();


$distanceMatrix = new GoogleDistanceMatrix('YOUR API KEY');
$distance = $distanceMatrix
    ->addOrigin('Van Bronckhorststraat 94, 5961SM Horst, The Netherlands')
    ->addDestination('Maistraße 10, 80337 München, Deutschland')
    ->setMode(GoogleDistanceMatrix::MODE_DRIVING)
    ->setLanguage('nl-NL')
    ->setUnits(GoogleDistanceMatrix::UNITS_METRIC)
    ->setAvoid(GoogleDistanceMatrix::AVOID_FERRIES)
    ->sendRequest();