From f8429d2a9dc81571bbb7cabcde12199ef9a4f984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Tobias=20de=20Freitas=20Neto?= Date: Tue, 26 Dec 2023 16:51:59 -0400 Subject: [PATCH] =?UTF-8?q?Retornando=20o=20dto=20no=20m=C3=A9todo=20getAd?= =?UTF-8?q?dressForCoordinates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Contracts/GeocodingServiceContract.php | 11 +++++++---- src/app/Services/GeocodingService.php | 16 +++++++++++++--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/app/Services/Contracts/GeocodingServiceContract.php b/src/app/Services/Contracts/GeocodingServiceContract.php index cfcf66e..d618b0e 100644 --- a/src/app/Services/Contracts/GeocodingServiceContract.php +++ b/src/app/Services/Contracts/GeocodingServiceContract.php @@ -16,9 +16,12 @@ interface GeocodingServiceContract public function getCoordinatesForAddress(string $address): GeocodingResponseData; /** - * @param float $latitude - * @param float $longitude - * @return array + * Retrieves the address for the given coordinates. + * + * @param float $latitude The latitude of the coordinates. + * @param float $longitude The longitude of the coordinates. + * + * @return GeocodingResponseData The address information for the given coordinates. */ - public function getAddressForCoordinates(float $latitude, float $longitude): array; + public function getAddressForCoordinates(float $latitude, float $longitude): GeocodingResponseData; } \ No newline at end of file diff --git a/src/app/Services/GeocodingService.php b/src/app/Services/GeocodingService.php index a473c47..c961bff 100644 --- a/src/app/Services/GeocodingService.php +++ b/src/app/Services/GeocodingService.php @@ -56,10 +56,20 @@ class GeocodingService implements GeocodingServiceContract * @param float $latitude The latitude of the coordinates. * @param float $longitude The longitude of the coordinates. * - * @return array The address information for the given coordinates. + * @return GeocodingResponseData The address information for the given coordinates. */ - public function getAddressForCoordinates(float $latitude, float $longitude): array + public function getAddressForCoordinates(float $latitude, float $longitude): GeocodingResponseData { - return $this->geocoder->getAddressForCoordinates($latitude, $longitude); + $response = $this->geocoder->getAddressForCoordinates($latitude, $longitude); + + $viewport = array_key_exists('viewport', $response) + ? get_object_vars($response['viewport']) + : []; + + $response['viewport'] = $viewport; + + return GeocodingResponseData::from( + $response + ); } } \ No newline at end of file