diff --git a/src/SmartIpLocation.php b/src/SmartIpLocation.php --- a/src/SmartIpLocation.php +++ b/src/SmartIpLocation.php @@ -200,6 +200,17 @@ * {@inh eritdoc} */ public function set(string $key, mixed $value): SmartIpLocationInterface|static { + // Country DB lookups may return empty strings or numeric strings for + // lat/lon. Normalize before assigning to typed float properties. + if (in_array($key, ['latitude', 'longitude'], TRUE)) { + if ($value === '' || $value === NULL) { + return $this; + } + if (is_string($value) || is_numeric($value)) { + $value = (float) $value; + } + } + if (isset($this->{$key})) { $this->{$key} = $value; $this->allData[$key] = $value;