Vyhľadávanie a find place
Tri spôsoby, ako objavovať miesta — všetky vracajú objekty Place:
use RoundlyConsulting\GooglePlaces\DataTransferObjects\Location;
use RoundlyConsulting\GooglePlaces\DataTransferObjects\NearbySearchQuery;
use RoundlyConsulting\GooglePlaces\DataTransferObjects\TextSearchQuery;
use RoundlyConsulting\GooglePlaces\Facades\GooglePlaces;
// Text search → Collection<Place>
$places = GooglePlaces::textSearch('pizza in Bratislava');
$places = GooglePlaces::textSearch(
(new TextSearchQuery('vegan brunch'))->openNow()->withMinRating(4.0)->take(10),
);
// Nearby search → Collection<Place> (radius 0–50000 m)
$places = GooglePlaces::nearbySearch(
(new NearbySearchQuery(new Location(48.1486, 17.1077), radius: 1500))
->withinTypes('cafe')
->rankBy('DISTANCE'),
);
// Find a single best match → ?Place
$place = GooglePlaces::findPlace('Eiffel Tower');findPlace() spustí textové vyhľadávanie s jedným výsledkom. Ako druhý argument môžete odovzdať Location — zhoda potom uprednostní kruh s polomerom 5 km okolo neho:
// Bias the match toward a point (a 5 km circle around it):
$place = GooglePlaces::findPlace('Old Town Hall', new Location(48.1486, 17.1077));Voľby textového vyhľadávania
$query = (new TextSearchQuery('pizza'))
->inLanguage('sk')
->inRegion('sk')
->ofType('restaurant') // a single included type
->openNow()
->withMinRating(4.0)
->take(20); // page size
$places = GooglePlaces::textSearch($query);| Metóda | Účinok |
|---|---|
withText(string $text) | Nahradí hľadaný text. |
inLanguage(string $language) | Jazyk odpovede (predvolene en). |
inRegion(string $region) | Kód regiónu. |
take(int $pageSize) | Veľkosť stránky. |
ofType(string $type) | Jeden zahrnutý typ miesta. |
openNow(bool $openNow = true) | Len práve otvorené miesta. |
withMinRating(float $rating) | Minimálne priemerné hodnotenie. |
withPriceLevels(string ...$levels) | Cenové úrovne Google, odovzdané bez zmeny. |
preferInArea() / restrictTo() | Preferovaná / obmedzená oblasť (LocationDefinition). |
nearby() / withinBounds() | Skratky pre preferovaný kruh / obmedzenie na obdĺžnik. |
rankBy(string $preference) | Poradie výsledkov podľa Google, odovzdané bez zmeny. |
withPageToken(string $token) | Načíta konkrétnu stránku. |
Voľby okolitého vyhľadávania
$query = (new NearbySearchQuery(new Location(48.1486, 17.1077), radius: 1500))
->withinTypes('cafe', 'bakery')
->excludingTypes('restaurant')
->take(10) // max result count
->inLanguage('sk');
$places = GooglePlaces::nearbySearch($query);| Metóda | Účinok |
|---|---|
new NearbySearchQuery(Location $location, int $radius = 5000) | Stred a polomer v metroch (0–50000, inak PlacesException). |
withRadius(int $radius) | Zmení polomer. |
withinTypes(string ...$types) | Zahrnuté typy miest. |
excludingTypes(string ...$types) | Vylúčené typy miest. |
take(int $max) | Maximálny počet výsledkov. |
rankBy(string $preference) | Poradie výsledkov podľa Google, napr. DISTANCE. |
inLanguage(string $language) | Jazyk odpovede (predvolene en). |
Pomocníci pre oblasť
Textové vyhľadávanie môžete fluentne nasmerovať alebo obmedziť:
use RoundlyConsulting\GooglePlaces\DataTransferObjects\Location;
use RoundlyConsulting\GooglePlaces\DataTransferObjects\TextSearchQuery;
(new TextSearchQuery('coffee'))->nearby(48.1486, 17.1077, radius: 2000); // circle bias
(new TextSearchQuery('coffee'))->withinBounds(new Location(48.1, 17.0), new Location(48.2, 17.2)); // rectangle restrictionStránkovanie
Textové vyhľadávanie vráti najviac 60 výsledkov; na ručný prechod jednou stránkou odovzdajte page token:
$next = GooglePlaces::textSearch((new TextSearchQuery('pizza'))->withPageToken($token));Alebo nechajte balík sledovať nextPageToken za vás. all() načíta všetky stránky naraz; cursor() vráti LazyCollection, ktorá načítava stránky podľa potreby; pages() vracia jednu kolekciu na stránku. Všetky tri rešpektujú bezpečnostný strop pagination.max_pages (predvolene 5) — pri jeho dosiahnutí sa stránkovanie zastaví a zaloguje sa varovanie:
use RoundlyConsulting\GooglePlaces\DataTransferObjects\Place;
use RoundlyConsulting\GooglePlaces\Facades\GooglePlaces;
// Eagerly collect every page into one collection:
$all = GooglePlaces::textSearchPaginated('museums in Bratislava')->all();
// Stream lazily — only fetches the next page when you ask for more places:
GooglePlaces::textSearchPaginated('museums')
->cursor()
->each(function (Place $place): void {
// ...
});
// Stop early — pages beyond the first 25 places are never requested:
$first = GooglePlaces::textSearchPaginated('museums')->cursor()->take(25)->collect();
// Page by page — each item is a Collection<Place>:
foreach (GooglePlaces::textSearchPaginated('museums')->pages() as $page) {
// one billed request per page
}
// Nearby search returns a single page (the New API does not paginate it):
$all = GooglePlaces::nearbySearchPaginated($nearbyQuery)->all();Prejavte lásku k open source
Tento balík je zadarmo pod licenciou MIT. Ak vám šetrí čas, jednorazový príspevok alebo členstvo na Patreone nám pomôže ho ďalej udržiavať, testovať a dokumentovať.
Ďalšie spôsoby podpory vrátane kryptomienOdoslaním daru súhlasíte s našimi podmienkami prijímania darov.
Chcete to zabudovať do svojho produktu?
Naše balíky integrujeme do zákazkových Laravel a AI riešení. Napíšte nám, na čom pracujete, a ozveme sa do 48 hodín.