PHP code example of wubs / simple-google-directions-api

1. Go to this page and download the library: Download wubs/simple-google-directions-api 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/ */

    

wubs / simple-google-directions-api example snippets



$options = new DirectionOptions(
            DirectionOption::origin($address1->latitude, $address1->longitude),
            DirectionOption::destination($address2->latitude, $address2->longitude),
            DirectionOption::mode(TravelModes::BICYCLING),
            DirectionOption::alternatives(true),
            DirectionOption::language("nl_NL"),
            DirectionOption::departureTime(Carbon::now())
        );
$routes = Directions::route($options);



$api = $app->make('\Wubs\Directions\Directions')

 namespace App\Http\Controllers;

use Wubs\Directions\Directions;

class DirectionsController extends Controller
{
   private $api;
   
    public function __construct(Directions $directions)
    {
        $this->directions = $directions;
        
    }
}


Wubs\Directions\Directions;

$directions = new Directions(getenv("GOOGLE_DIRECTIONS_SERVER_KEY"));

$zipApi = new Wubs\Zip\ZipApi(getenv("ZIP_API_KEY"));
$address1 = $zipApi->address("8316PB", 28);
$address2 = $zipApi->address("6821HX", 1);

$options = new DirectionOptions(
    DirectionOption::origin($address1->latitude, $address1->longitude),
    DirectionOption::destination($address2->latitude, $address2->longitude),
    DirectionOption::mode(TravelModes::BICYCLING),
    DirectionOption::alternatives(true),
    DirectionOption::language("nl_NL"),
    DirectionOption::departureTime(Carbon::now())
);

$response = $directions->route($options);
bash
php artisan vendor:publish