From 2ccf2757e246227aff5db437501e5cfce90f4e67 Mon Sep 17 00:00:00 2001 From: "Zeeshan Ali (Khattak)" Date: Tue, 7 Apr 2015 18:13:42 +0100 Subject: [PATCH] locator: Move speed/heading setting to source Move calculation and setting of speed and heading to gclue_location_source_set_location(). We ensure that speed and heading are only calculated if they are not already set on the new location object so that they are not re-calculated each time location is set from one source to another (keeping in mind that Locator is also a LocationSource subclass). This change would mean that speed and heading are only set by the source it originates from. i-e speed and heading are not calculated by comparing location from two different sources, which would typically be wrong as different locations from different sources just means the same location but with different accuracies. For example, WiFi source will put me at Crystal Palace but soon after GPS will put me at Westow House (a pub in Crystal Palace) but I'm not moving so deriving speed and heading from these two locations would be wrong. As a positive side-effect, this would make it possible for sources to provide the speed and accuracy themselves. This would be at least possible for GPS (see bug#89907). Known issue: We still end up with these properties being computed by Locator by comparison of locations from two different sources if the latest location is the first location from a source. We solve this issue in a following patch. https://bugs.freedesktop.org/show_bug.cgi?id=89852 --- src/gclue-location-source.c | 30 +++++++++++++++++++++++------- src/gclue-locator.c | 3 --- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/gclue-location-source.c b/src/gclue-location-source.c index bbfed24..48c6950 100644 --- a/src/gclue-location-source.c +++ b/src/gclue-location-source.c @@ -266,19 +266,35 @@ gclue_location_source_set_location (GClueLocationSource *source, GClueLocation *location) { GClueLocationSourcePrivate *priv = source->priv; + GClueLocation *cur_location; GeocodeLocation *gloc; + gdouble speed, heading; + cur_location = priv->location; gloc = GEOCODE_LOCATION (location); - priv->location = gclue_location_new + priv->location = gclue_location_new_with_description (geocode_location_get_latitude (gloc), geocode_location_get_longitude (gloc), - geocode_location_get_accuracy (gloc)); + geocode_location_get_accuracy (gloc), + geocode_location_get_description (gloc)); + + speed = gclue_location_get_speed (location); + if (speed == GCLUE_LOCATION_SPEED_UNKNOWN) { + if (cur_location != NULL) + gclue_location_set_speed_from_prev_location + (priv->location, cur_location); + } else { + gclue_location_set_speed (priv->location, speed); + } - g_object_set (priv->location, - "description", geocode_location_get_description (gloc), - "speed", gclue_location_get_speed (location), - "heading", gclue_location_get_heading (location), - NULL); + heading = gclue_location_get_heading (location); + if (heading == GCLUE_LOCATION_HEADING_UNKNOWN) { + if (cur_location != NULL) + gclue_location_set_heading_from_prev_location + (priv->location, cur_location); + } else { + gclue_location_set_heading (priv->location, heading); + } g_object_notify (G_OBJECT (source), "location"); g_clear_object (&cur_location); diff --git a/src/gclue-locator.c b/src/gclue-locator.c index 3df0ebf..e7175c8 100644 --- a/src/gclue-locator.c +++ b/src/gclue-locator.c @@ -96,9 +96,6 @@ set_location (GClueLocator *locator, return; } - gclue_location_set_speed_from_prev_location (location, cur_location); - gclue_location_set_heading_from_prev_location (location, cur_location); - gclue_location_source_set_location (GCLUE_LOCATION_SOURCE (locator), location); } -- 2.1.0