A direction request is the starting point when you want to request a direction.
First of all, if you want to route a direction, you will need to build a direction request. So let's go:
use Ivory\GoogleMap\Service\Base\Location\AddressLocation;
use Ivory\GoogleMap\Service\Direction\DirectionRequest\Request;
$request = new DirectionRequest(
new AddressLocation('New York'),
new AddressLocation('Washington')
);
The direction request constructor requires an origin as first argument and a destination as second argument.
If you want to update the origin, you can use:
use Ivory\GoogleMap\Service\Base\Location\AddressLocation;
$request->setOrigin(new AddressLocation('New York'));
The origin is represented by the LocationInterface
. If you want to learn more about it, you can read its
documentation.
If you want to update the destination, you can use:
use Ivory\GoogleMap\Service\Base\Location\AddressLocation;
$request->setDestination(new AddressLocation('Washington'));
The destination is represented by the LocationInterface
. If you want to learn more about it, you can read its
documentation.
If you want to provide a departure time, you can use:
$request->setDepartureTime(new \DateTime());
If you want to provide an arrival time, you can use:
$request->setDepartureTime(new \DateTime());
If you want to add waypoint to your direction, you can use:
use Ivory\GoogleMap\Service\Base\Location\AddressLocation;
use Ivory\GoogleMap\Service\Direction\Request\DirectionWaypoint;
$request->addWaypoint(new DirectionWaypoint(new AddressLocation('Philadelphia')));
The waypoint accepts a LocationInterface
as first argument. If you want to learn more about it, you can read its
documentation.
If you want to optimize waypoints, you can use:
$request->setOptimizeWaypoints(true);
If you want to avoid tolls, highways ferries or indoor, you can use:
use Ivory\GoogleMap\Service\Base\Avoid;
$request->setAvoid(Avoid::HIGHWAYS);
If you want to have route alternatives, you can use:
$request->setProvideRouteAlternatives(true);
If you want to define your travel mode, you can use:
use Ivory\GoogleMap\Service\Base\TravelMode;
$request->setTravelMode(TravelMode::DRIVING);
If you want to define your traffic model, you can use:
use Ivory\GoogleMap\Service\Base\TrafficModel;
$request->setTrafficModel(TrafficModel::BEST_GUESS);
If you want to define your transit modes, you can use:
use Ivory\GoogleMap\Service\Base\TransitMode;
$request->setTransitModes([
TransitMode::BUS,
TransitMode::TRAIN,
]);
If you want to define your transit routing preference, you can use:
use Ivory\GoogleMap\Service\Base\TransitRoutingPreference;
$request->setTransitRoutingPreference(TransitRoutingPreference::LESS_WALKING);
If you want to update the unit system, you can use:
use Ivory\GoogleMap\Service\Base\UnitSystem;
$request->setUnitSystem(UnitSystem::METRIC);
If you want to update the region, you can use:
$request->setRegion('us');
If you want to update the language, you can use:
$request->setLanguage('fr');