Add point data class
This commit is contained in:
parent
132d15f368
commit
e924be87df
|
@ -13,13 +13,14 @@ class Address
|
|||
) {
|
||||
}
|
||||
|
||||
public function getCoordinate(): ?Coordinate
|
||||
public function getCoordinate(): ?Point
|
||||
{
|
||||
if (!$this->address || !$this->zip || !$this->location) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$response = Http::get('https://nominatim.openstreetmap.org/search/'.rawurlencode($this->queryString()).'?'.http_build_query([
|
||||
$response = Http::get('https://nominatim.openstreetmap.org/search?' . http_build_query([
|
||||
'q' => $this->queryString(),
|
||||
'format' => 'json',
|
||||
'addressdetails' => 1,
|
||||
]));
|
||||
|
@ -28,10 +29,7 @@ class Address
|
|||
return null;
|
||||
}
|
||||
|
||||
$lat = (float) data_get($response, '0.lat');
|
||||
$lon = (float) data_get($response, '0.lon');
|
||||
|
||||
return new Coordinate($lat, $lon);
|
||||
return count($response->json()) ? Point::from(['lat' => (float) data_get($response, '0.lat'), 'lon' => (float) data_get($response, '0.lon')]) : null;
|
||||
}
|
||||
|
||||
public function queryString(): string
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace Zoomyboy\Osm;
|
|||
|
||||
interface Geolocatable
|
||||
{
|
||||
public function fillCoordinate(Coordinate $coordinate): void;
|
||||
public function fillCoordinate(Point $point): void;
|
||||
|
||||
public function getAddressForGeolocation(): ?Address;
|
||||
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
namespace Zoomyboy\Osm;
|
||||
|
||||
class Coordinate
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
class Point extends Data
|
||||
{
|
||||
public function __construct(public float $lat, public float $lon)
|
||||
{
|
Loading…
Reference in New Issue