1. Go to this page and download the library: Download sysborg/gmaps-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sysborg / gmaps-laravel example snippets
use Sysborg\GmapsLaravel\Facades\GMap;
use Sysborg\GmapsLaravel\DTOs\Coordinate;
$response = GMap::nearbySearch(
coordinate: new Coordinate(-23.5505, -46.6333),
radius: 1500, // meters
type: 'restaurant', // optional
keyword: 'pizza', // optional
);
foreach ($response->places as $place) {
echo $place->name; // "Pizzaria Italia"
echo $place->vicinity; // "Rua Augusta, 100"
echo $place->rating; // 4.5
echo $place->location->latitude;
echo $place->location->longitude;
}
if ($response->hasNextPage()) {
// fetch next page using $response->nextPageToken
}
use Sysborg\GmapsLaravel\UseCases\Places\NearbySearchUseCase;
use Sysborg\GmapsLaravel\DTOs\Coordinate;
use Sysborg\GmapsLaravel\DTOs\Places\NearbySearchRequest;
class FindNearbyRestaurantsAction
{
public function __construct(private readonly NearbySearchUseCase $useCase) {}
public function handle(float $lat, float $lng): array
{
$response = $this->useCase->execute(new NearbySearchRequest(
coordinate: new Coordinate($lat, $lng),
radius: 1500,
type: 'restaurant',
));
return $response->toArray();
}
}