Skip to content

flofloflo/laravel-distancematrix-ai

Repository files navigation

Laravel wrapper for the DISTANCEMATRIX.AI API

Fetches estimated travel time and distance for multiple destinations from the DISTANCEMATRIX.AI API.

Installation

You can install the package via composer VCS (package currently not available via packagist):

{
  "repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/flofloflo/laravel-distancematrix-ai"
    }
  ],
  "require": {
    "mybit/laravel-distancematrix-ai": "dev-master"
  }
}

You can publish the config file with:

php artisan vendor:publish --provider="Mybit\LaravelDistancematrixAi\DistanceMatrixServiceProvider" --tag="config"

This is the contents of the published config file:

use Mybit\LaravelDistancematrixAi\DistanceMatrix;

return [
     /**
     * The API key which should be used for calls to the DISTANCEMATRIX.AI API
     */
    'api_key' => env('DISTANCEMATRIX_API_KEY', null),

    /**
     * Default values
     */
    'defaults' => [
        // The language which is used for returning the results
        // see https://distancematrix.ai/dev#request_parameters for a list of supported values
        'language' => 'en',
        // Unit system used for distances
        'units' => DistanceMatrix::UNITS_METRIC,
        // Driving mode used for distance calculation
        'mode' => DistanceMatrix::MODE_DRIVING,
        // Route restrictions
        'avoid' => null,
    ]
];

Usage (DistanceMatrix API)

use Mybit\LaravelDistancematrixAi\Facades\DistanceMatrix;

$distanceResponse = DistanceMatrix::setLanguage('de')
    ->setOrigin('53.54942880970846, 9.95784213616111')
    ->setDestination('53.549626412962326, 9.968088174277717')
    ->sendRequest();

Heads up: When using addOrigin() or addDestination() in combination with the facade, you can end up querying the locations of the previous call(s), as the facade will return the same DistanceMatrix instance for the complete application request lifecycle. To prevent this, use setOrigin() / setDestination() at the beginning of your query as they will reset the internal origins/destinations array.

Usage (Geocoding API)

See https://distancematrix.ai/geo for more information on the geocoding API.

use Mybit\LaravelDistancematrixAi\Facades\Geocoding;

$geocodingResponse = Geocoding::setLanguage('de')
    ->setAddress('1600 Amphitheatre Parkway, Mountain View, CA')
    ->setBounds(-124.48200307,32.52952353,-114.13078164,42.00949894)
    ->sendRequest();

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

Laravel wrapper for distancematrix.ai service

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages