---
title: "Súradnice, dopyty a enumy — Geolocation for Laravel | Roundly"
description: "Validovaný hodnotový objekt Coordinates, vzdialenosť podľa Haversina, pomenované konštruktory GeolocationQuery a DistanceQuery a oba enumy."
url: https://roundly-consulting.com/sk/open-source/navody/geolocation-for-laravel/suradnice
language: sk
---

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

[Geolocation for Laravel](https://roundly-consulting.com/sk/open-source/navody/geolocation-for-laravel.md)

# Súradnice, dopyty a enumy

Coordinates je nemenný hodnotový objekt, ktorý pri vytvorení overí rozsah a vypočíta vzdialenosť po hlavnej kružnici:

```php
use RoundlyConsulting\Geolocation\DataTransferObjects\Coordinates;

$here = new Coordinates(48.1486, 17.1077);   // validates lat ∈ [-90,90], lng ∈ [-180,180]
$same = Coordinates::make(48.1486, 17.1077); // static constructor, same validation

$metres = $here->distanceTo(new Coordinates(50.0755, 14.4378)); // Haversine, ≈ 290 km

$here->latitude;    // 48.1486
$here->toArray();   // ['latitude' => 48.1486, 'longitude' => 17.1077]

new Coordinates(91.0, 17.1077); // throws InvalidCoordinatesException
```

## Dopyty

GeolocationQuery má forIp(), forAddress() a forCoordinates(); DistanceQuery má between() s predvoleným spôsobom dopravy Driving:

```php
use RoundlyConsulting\Geolocation\DataTransferObjects\DistanceQuery;
use RoundlyConsulting\Geolocation\DataTransferObjects\GeolocationQuery;
use RoundlyConsulting\Geolocation\Enum\DistanceType;

$query = GeolocationQuery::forCoordinates($here);
$query->coordinates();   // ?Coordinates — null for IP and address queries
$query->ipAddress;       // ?string
$query->address;         // ?string

$trip = DistanceQuery::between(from: $here, to: $there, type: DistanceType::Walking);
$trip->from();           // Coordinates
$trip->to();             // Coordinates

// Positional constructors work too:
new GeolocationQuery('203.0.113.7');
new DistanceQuery(48.1, 17.1, 50.0, 14.4, DistanceType::Driving);
```

## Enumy

DistanceType (Walking, Driving) a GeolocationType (Default, IP, Geolocation) sú enumy s reťazcovými hodnotami a používajú trait Helpers z enums-for-laravel, takže values(), labels(), options() / toOptions(), validationRule(), tryFromName(), is() / isIn() a stráže when\* dostanete zadarmo:

```php
use RoundlyConsulting\Geolocation\Enum\DistanceType;
use RoundlyConsulting\Geolocation\Enum\GeolocationType;

DistanceType::values()->all();        // ['Walking', 'Driving']
DistanceType::validationRule();       // 'in:Walking,Driving'
DistanceType::toOptions()->all();     // ['Walking' => 'Walking', 'Driving' => 'Driving'] — ready for <select>
DistanceType::tryFromName('Driving'); // DistanceType::Driving

GeolocationType::values()->all();     // ['Default', 'IP', 'Geolocation']
GeolocationType::Ip->value;           // 'IP' (wire value is preserved)
GeolocationType::Ip->readable();      // 'IP'
```

## 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/geolocation-for-laravel.md)
