From 6ccd36d89963bc3adfaeeec2389535970f52b0f7 Mon Sep 17 00:00:00 2001 From: Kalev Lember Date: Sat, 7 Sep 2013 18:25:12 +0200 Subject: [PATCH 1/2] locator: Really take distance threshold into account This fixes several issues that led to ignoring the DistanceThreshold value most of the time: - we were ignoring the threshold value when the description from the IP geolocation service changed; - double equality comparison was done with == and not taking epsilon into account; - location threshold was interpreted in km, whereas most application authors expect it to be in meters. https://bugs.freedesktop.org/show_bug.cgi?id=69105 --- src/gclue-locator.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/gclue-locator.c b/src/gclue-locator.c index ccb30d6..626e5f1 100644 --- a/src/gclue-locator.c +++ b/src/gclue-locator.c @@ -21,10 +21,13 @@ */ #include +#include #include "gclue-locator.h" #include "gclue-ipclient.h" +#define EPSILON (1e-10) + /* This class will be responsible for doing the actual geolocating. */ G_DEFINE_TYPE (GClueLocator, gclue_locator, G_TYPE_OBJECT) @@ -160,21 +163,19 @@ static void gclue_locator_update_location (GClueLocator *locator, GClueLocationInfo *location) { - gdouble accuracy, new_accuracy, distance; - const char *desc, *new_desc; + gdouble accuracy, new_accuracy; + gdouble distance_km, threshold_km; if (locator->priv->location == NULL) goto update; accuracy = gclue_location_info_get_accuracy (locator->priv->location); new_accuracy = gclue_location_info_get_accuracy (location); - desc = gclue_location_info_get_description (locator->priv->location); - new_desc = gclue_location_info_get_description (location); - distance = gclue_location_info_get_distance_from + distance_km = gclue_location_info_get_distance_from (locator->priv->location, location); - if (accuracy == new_accuracy && - g_strcmp0 (desc, new_desc) == 0 && - distance < locator->priv->threshold) { + threshold_km = locator->priv->threshold / 1000.0; + if (distance_km < threshold_km && + fabs (accuracy - new_accuracy) < EPSILON) { g_debug ("Location remain unchanged"); return; } -- 1.8.3.1