LocationService client
This page contains examples with the LocationService client. See the client introduction for a more detailed description how to use a client. You may also want to consider the authentication documentation to understand the many ways you can authenticate with AWS.
The LocationService package could be installed with Composer.
composer require async-aws/location-service
A new client object may be instantiated by:
use AsyncAws\LocationService\LocationServiceClient;
$locationService = new LocationServiceClient();
The authentication parameters is read from the environment by default. You can also specify a AWS access id and secret:
use AsyncAws\LocationService\LocationServiceClient;
$locationService = new LocationServiceClient([
'accessKeyId' => 'my_access_key',
'accessKeySecret' => 'my_access_secret',
'region' => 'eu-central-1',
]);
For all available options, see the configuration reference.
Usage¶
CalculateRoute¶
use AsyncAws\LocationService\LocationServiceClient;
use AsyncAws\LocationService\Enum\DimensionUnit;
use AsyncAws\LocationService\Enum\DistanceUnit;
use AsyncAws\LocationService\Enum\TravelMode;
use AsyncAws\LocationService\Enum\VehicleWeightUnit;
use AsyncAws\LocationService\Input\CalculateRouteRequest;
use AsyncAws\LocationService\ValueObject\CalculateRouteTruckModeOptions;
use AsyncAws\LocationService\ValueObject\TruckDimensions;
use AsyncAws\LocationService\ValueObject\TruckWeight;
$location = new LocationServiceClient();
$request = $location->calculateRoute(new CalculateRouteRequest([
'CalculatorName' => 'CalculatorName',
'DepartNow' => false,
'DeparturePosition' => [-123.115, 49.285],
'DepartureTime' => new \DateTimeImmutable('2023-06-27T06:17:31+00:00'),
'DestinationPosition' => [-123.115, 49.285],
'DistanceUnit' => DistanceUnit::KILOMETERS,
'IncludeLegGeometry' => false,
'TravelMode' => TravelMode::TRUCK,
'TruckModeOptions' => new CalculateRouteTruckModeOptions([
'AvoidFerries' => false,
'AvoidTolls' => false,
'Dimensions' => new TruckDimensions([
'Height' => 4,
'Length' => 20,
'Unit' => DimensionUnit::METERS,
'Width' => 3,
]),
'Weight' => new TruckWeight([
'Total' => 20000,
'Unit' => VehicleWeightUnit::KILOGRAMS,
]),
]),
'WaypointPositions' => [[-123.115, 49.285]],
]));
$request->getSummary();
The source code to this page is found on GitHub.