---
title: "Vyhľadávanie a find place — Google Places for Laravel | Roundly"
description: "Textové a okolité vyhľadávanie a find place — s filtrami, preferovanou oblasťou, page tokenmi a lenivým stránkovaním so stropom."
url: https://roundly-consulting.com/sk/open-source/navody/google-places-for-laravel/vyhladavanie
language: sk
---

[Všetky balíky](https://roundly-consulting.com/sk/open-source.md)

[Google Places for Laravel](https://roundly-consulting.com/sk/open-source/navody/google-places-for-laravel.md)

# Vyhľadávanie a find place

Tri spôsoby, ako objavovať miesta — všetky vracajú objekty Place:

```php
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:

```php
// 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

```php
$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. |
| `fresh(bool $fresh = true)` | Preskočí čítanie z cache a odpoveď do nej zapíše (pozrite Cache odpovedí). |

## Voľby okolitého vyhľadávania

```php
$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). |
| `fresh(bool $fresh = true)` | Preskočí čítanie z cache a odpoveď do nej zapíše (pozrite Cache odpovedí). |

## Pomocníci pre oblasť

Textové vyhľadávanie môžete fluentne nasmerovať alebo obmedziť:

```php
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 restriction
```

## Stránkovanie

Textové vyhľadávanie vráti najviac 60 výsledkov; na ručný prechod jednou stránkou odovzdajte page token:

```php
$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:

```php
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 kryptomien](https://roundly-consulting.com/sk/podporte-nas.md)

Odoslaním daru súhlasíte s našimi [podmienkami prijímania darov](https://roundly-consulting.com/sk/podmienky-darov.md).

[Podporte našu open-source prácu (otvorí sa v novej karte)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Pridajte sa k nám na Patreone (otvorí sa v novej karte)](https://www.patreon.com/cw/roundly)

## 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.

[Ponuka do 48 hodín](https://roundly-consulting.com/sk/kontakt.md) [Prezrieť všetky balíky](https://roundly-consulting.com/sk/open-source/navody/google-places-for-laravel.md)
