php-google-maps-distance-matrix
php-google-maps-distance-matrix copied to clipboard
Use in laravel controller
Can you tell me how can I use it in laravel Controller
The readme does a decent job of explaining how one can use this library, but I hope the following example of a controller method helps:
public function index() {
$response = DistanceMatrix::license($license)
->addOrigin('norwich,gb')
->addDestination('52.603669, 1.223785')
->request();
$rows = $response->rows();
$elements = $rows[0]->elements();
$element = $element[0];
$distance = $element->distance();
$duration = $element->duration();
return View('my.view'), [
'distance' => $distance,
'duration' => $duration,
// and add any additional variables you want from the API here
];
}