From 6478ffbe88153ed5f1162104b7bbca4d86c52f97 Mon Sep 17 00:00:00 2001 From: erkurn Date: Tue, 27 Sep 2022 08:16:21 +0000 Subject: [PATCH] Fix styling --- config/filament-address-picker.php | 2 +- src/Forms/Components/AddressPicker.php | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/config/filament-address-picker.php b/config/filament-address-picker.php index 5c60828..7af4f8e 100644 --- a/config/filament-address-picker.php +++ b/config/filament-address-picker.php @@ -1,5 +1,5 @@ "", + 'google_map_key' => '', ]; diff --git a/src/Forms/Components/AddressPicker.php b/src/Forms/Components/AddressPicker.php index 1a857dc..6c6d41c 100644 --- a/src/Forms/Components/AddressPicker.php +++ b/src/Forms/Components/AddressPicker.php @@ -5,10 +5,8 @@ use Cache\Adapter\PHPArray\ArrayCachePool; use Filament\Forms\Components\Concerns\HasPlaceholder; use Filament\Forms\Components\Field; -use Geocoder\Model\AddressCollection; use Geocoder\Provider\Cache\ProviderCache; use Geocoder\Provider\GoogleMaps\GoogleMaps; -use Geocoder\Provider\GoogleMaps\Model\GoogleAddress; use Geocoder\Query\ReverseQuery; use GuzzleHttp\Client; @@ -30,7 +28,7 @@ class AddressPicker extends Field 'streetViewControl' => true, 'rotateControl' => true, 'fullscreenControl' => true, - 'searchBoxControl' => false + 'searchBoxControl' => false, ]; public array $defaultLocation = [ @@ -84,24 +82,25 @@ public function getApiKey() return config('filament-address-picker.google_map_key'); } - public function getAddresses() : \Geocoder\Collection + public function getAddresses(): \Geocoder\Collection { $httpClient = new Client(); $provider = new GoogleMaps($httpClient, null, $this->getApiKey()); $cachedProvider = new ProviderCache( $provider, new ArrayCachePool(), - 60 * 60 * 24 + 60 * 60 * 24 ); $geocoder = new \Geocoder\StatefulGeocoder($cachedProvider, 'en'); + return $geocoder->reverseQuery(ReverseQuery::fromCoordinates( data_get($this->getState(), 'lat'), data_get($this->getState(), 'lng') )); } - public function getAddress() : \Geocoder\Location + public function getAddress(): \Geocoder\Location { return $this->getAddresses()->first(); } @@ -118,7 +117,7 @@ public function getState() } catch (\Exception $e) { return [ 'lat' => 0, - 'lng' => 0 + 'lng' => 0, ]; } }