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