Fetches estimated travel time and distance for multiple destinations from the DISTANCEMATRIX.AI API.
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,
]
];
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.
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();
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
- Final Bytes - I used his google-distance-matrix-api package as starting point for this implementation
- Florian Heller
- All Contributors
The MIT License (MIT). Please see License File for more information.