diff --git a/plugins/UserCountry/VisitorGeolocator.php b/plugins/UserCountry/VisitorGeolocator.php index 78446408c22fda451742f88e0c0c94e7d97e2940..b6105349d851e347543dd4704adf1398999d4793 100644 --- a/plugins/UserCountry/VisitorGeolocator.php +++ b/plugins/UserCountry/VisitorGeolocator.php @@ -36,6 +36,8 @@ require_once PIWIK_INCLUDE_PATH . "/plugins/UserCountry/LocationProvider.php"; */ class VisitorGeolocator { + const LAT_LONG_COMPARE_EPSILON = 0.0001; + /** * @var string[] */ @@ -190,7 +192,7 @@ class VisitorGeolocator $locationPropertyValue = $location[$locationKey]; $existingPropertyValue = $row[$column]; - if ($locationPropertyValue != $existingPropertyValue) { + if (!$this->areLocationPropertiesEqual($locationKey, $locationPropertyValue, $existingPropertyValue)) { $valuesToUpdate[$column] = $locationPropertyValue; } } @@ -213,6 +215,19 @@ class VisitorGeolocator return $this->backupProvider; } + private function areLocationPropertiesEqual($locationKey, $locationPropertyValue, $existingPropertyValue) + { + if (($locationKey == LocationProvider::LATITUDE_KEY + || $locationKey == LocationProvider::LONGITUDE_KEY) + && $existingPropertyValue != 0 + ) { + // floating point comparison + return abs(($locationPropertyValue - $existingPropertyValue) / $existingPropertyValue) < self::LAT_LONG_COMPARE_EPSILON; + } else { + return $locationPropertyValue == $existingPropertyValue; + } + } + private function getDefaultProvider() { return LocationProvider::getProviderById(DefaultProvider::ID);