PHP code example of canaltp / navitia

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

    

canaltp / navitia example snippets

 php
namespace App\Service;

use Navitia\Component\Service\ServiceFacade;

class Navitia
{
    private ServiceFacade $navitiacomponent;

    function __construct(ServiceFacade $navitiacomponent)
    {
        $this->navitiacomponent = $navitiacomponent;
        // Configuration
        $config = array(
            'url' => 'api.navitia.io',
            'token' => '3b036afe-4242-abcd-4242-99718476c2e0', // Example of token
        );
        $this->navitiacomponent->setConfiguration($config);
    }
}
 php
$query = array(
    'api' => 'journeys',
    'parameters' => array(
        'from' => '2.3749036;48.8467927',
        'to' => '2.2922926;48.8583736',
    ),
);

$result = $this->navitiacomponent->call($query); // Returns an object with Api result
 php
$query = array(
    'api' => 'journeys',
    'parameters' => array(
        'from' => '2.3749036;48.8467927',
        'to' => '2.2922926;48.8583736',
    ),
);

$result = $this->navitiacomponent->call($query);
 php
$query = array(
    'api' => 'coverage',
    'parameters' => array(
        'region' => 'sandbox',
    ),
);

$result = $this->navitiacomponent->call($query);
 php
$query = array(
    'api' => 'departures',
    'parameters' => array(
        'region' => 'sandbox',
        'path_filter' => '/lines/line:RAT:M1/departures?from_datetime=20160615T1337'
    ),
);

$result = $this->navitiacomponent->call($query);
 php
$query = array(
    'api' => 'coverage',
    'parameters' => array(
        'region' => 'sandbox',                          // Coverage name
        'path_filter' => 'stop_areas?variable=value',   // Url to call
    ),
);

$result = $this->navitiacomponent->call($query);
// Will call http://api.navitia.io/v1/coverage/sandbox/stop_areas?variable=value