A distance matrix request is the starting point when you want to process a distance matrix.
First of all, if you want to process a distance matrix, you will need to build a distance matrix request. So let's go:
use Ivory\GoogleMap\Service\Base\Location\AddressLocation;
use Ivory\GoogleMap\Service\DistanceMatrix\Request\DistanceMatrixRequest;
$request = new DistanceMatrixRequest(
[new AddressLocation('New York')],
[new AddressLocation('Washington')]
);
The distance matrix constructor requires an array of origins as first argument and an array of destinations as second argument.
If you want to update origins, you can use:
use Ivory\GoogleMap\Service\Base\Location\AddressLocation;
$request->setOrigins([new AddressLocation('New York')]);
The origins are represented by the LocationInterface
. If you want to learn more about it, you can read its
documentation.
If you want to update destinations, you can use:
use Ivory\GoogleMap\Service\Base\Location\AddressLocation;
$request->setDestinations([new AddressLocation('Washington')]);
The destinations are 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 avoid tolls, highways, ferries or indoor, you can use:
use Ivory\GoogleMap\Service\Base\Avoid;
$request->setAvoid(Avoid::HIGHWAYS);
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 choose a travel mode, you can use:
use Ivory\GoogleMap\Service\Base\TravelMode;
$request->setTravelMode(TravelMode::DRIVING);
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');