GeoIP2.php
public function geocodeQuery(GeocodeQuery $query): Collection
    {
        $address = $query->getText();
        $locale = $query->getLocale() ?: 'en'; // Default to English
        if (!filter_var($address, FILTER_VALIDATE_IP)) {
            throw new UnsupportedOperation('The GeoIP2 provider does not support street addresses, only IP addresses.');
        }

        if ('127.0.0.1' === $address) {
            return new AddressCollection([$this->getLocationForLocalhost()]);
        }

        $result = json_decode($this->executeQuery($address));

        if (null === $result) {
            return new AddressCollection([]);
        }

        $adminLevels = [];
        if (isset($result->subdivisions) && is_array($result->subdivisions)) {
            foreach ($result->subdivisions as $i => $subdivision) {
                $name = (isset($subdivision->names->{$locale}) ? $subdivision->names->{$locale} : null);
                $code = (isset($subdivision->iso_code) ? $subdivision->iso_code : null);

                if (null !== $name || null !== $code) {
                    $adminLevels[] = ['name' => $name, 'code' => $code, 'level' => $i + 1];
                }
            }
        }

        return new AddressCollection([
            Address::createFromArray([
                'providedBy' => $this->getName(),
                'countryCode' => (isset($result->country->iso_code) ? $result->country->iso_code : null),
                'country' => (isset($result->country->names->{$locale}) ? $result->country->names->{$locale} : null),
                'locality' => (isset($result->city->names->{$locale}) ? $result->city->names->{$locale} : null),
                'latitude' => (isset($result->location->latitude) ? $result->location->latitude : null),
                'longitude' => (isset($result->location->longitude) ? $result->location->longitude : null),
                'timezone' => (isset($result->location->time_zone) ? $result->location->time_zone : null),
                'postalCode' => (isset($result->postal->code) ? $result->postal->code : null),
                'adminLevels' => $adminLevels,
            ]),
        ]);
    }
public function geocodeQuery(GeocodeQuery $query): Collection
    {
        $address = $query->getText();
        $locale = $query->getLocale() ?: 'en'; // Default to English
        if (!filter_var($address, FILTER_VALIDATE_IP)) {
            throw new UnsupportedOperation('The GeoIP2 provider does not support street addresses, only IP addresses.');
        }

        if ('127.0.0.1' === $address) {
            return new AddressCollection([$this->getLocationForLocalhost()]);
        }

        $result = json_decode($this->executeQuery($address));

        if (null === $result) {
            return new AddressCollection([]);
        }

        $adminLevels = [];
        if (isset($result->subdivisions) && is_array($result->subdivisions)) {
            foreach ($result->subdivisions as $i => $subdivision) {
                $name = (isset($subdivision->names->{$locale}) ? $subdivision->names->{$locale} : null);
                $code = (isset($subdivision->iso_code) ? $subdivision->iso_code : null);

                if (null !== $name || null !== $code) {
                    $adminLevels[] = ['name' => $name, 'code' => $code, 'level' => $i + 1];
                }
            }
        }

        return new AddressCollection([
            Address::createFromArray([
                'providedBy' => $this->getName(),
                'countryCode' => (isset($result->country->iso_code) ? $result->country->iso_code : null),
                'country' => (isset($result->country->names->{$locale}) ? $result->country->names->{$locale} : null),
                'locality' => (isset($result->city->names->{$locale}) ? $result->city->names->{$locale} : null),
                'latitude' => (isset($result->location->latitude) ? $result->location->latitude : null),
                'longitude' => (isset($result->location->longitude) ? $result->location->longitude : null),
                'timezone' => (isset($result->location->time_zone) ? $result->location->time_zone : null),
                'postalCode' => (isset($result->postal->code) ? $result->postal->code : null),
                'adminLevels' => $adminLevels,
            ]),
        ]);
    }
{@inheritdoc}