diff options
author | diosmosis <benaka@piwik.pro> | 2015-03-16 22:20:39 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-03-16 22:20:39 +0300 |
commit | e43871cf0997ab90a1f7929aac0a89ccd38d9018 (patch) | |
tree | 3916ed8b7a9f700452fb21f7779d5e7b1417f519 | |
parent | 85077a6ec5dd29abec63c060caf985671127ae85 (diff) |
Correct floating point comparison for latitude/longitude in VisitorGeolocator when determining visit fields to update.
-rw-r--r-- | plugins/UserCountry/VisitorGeolocator.php | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/plugins/UserCountry/VisitorGeolocator.php b/plugins/UserCountry/VisitorGeolocator.php index 78446408c2..b6105349d8 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); |