aboutsummaryrefslogtreecommitdiffstats
path: root/mobile-widgets/qmlmapwidgethelper.cpp
diff options
context:
space:
mode:
authorGravatar Lubomir I. Ivanov <neolit123@gmail.com>2017-07-24 02:49:11 +0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-07-28 07:31:11 -0700
commit4b8b61100aba6a2457a1b3c36868fcb39b1c5b8a (patch)
tree90d9c59b3fa64f50edb564e0880240226def0c71 /mobile-widgets/qmlmapwidgethelper.cpp
parent66b2f0c88cae13b295e0bd5f49374512e91fa628 (diff)
downloadsubsurface-4b8b61100aba6a2457a1b3c36868fcb39b1c5b8a.tar.gz
mapwidgethelper: skip dive sites which are near each other
Use QGeoCoordinate::distanceTo() to skip dive sites which are too close (50m) to dives sites which are already added as MapLocations. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Diffstat (limited to 'mobile-widgets/qmlmapwidgethelper.cpp')
-rw-r--r--mobile-widgets/qmlmapwidgethelper.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/mobile-widgets/qmlmapwidgethelper.cpp b/mobile-widgets/qmlmapwidgethelper.cpp
index 1bc884ecf..83a78582e 100644
--- a/mobile-widgets/qmlmapwidgethelper.cpp
+++ b/mobile-widgets/qmlmapwidgethelper.cpp
@@ -9,6 +9,8 @@
#include "core/divesite.h"
#include "qt-models/maplocationmodel.h"
+#define MIN_DISTANCE_BETWEEN_DIVE_SITES_M 50.0
+
MapWidgetHelper::MapWidgetHelper(QObject *parent) : QObject(parent)
{
m_mapLocationModel = new MapLocationModel(this);
@@ -36,9 +38,20 @@ void MapWidgetHelper::reloadMapLocations()
for_each_dive_site(idx, ds) {
if (!dive_site_has_gps_location(ds))
continue;
- const qreal longitude = ds->longitude.udeg / 1000000.0;
- const qreal latitude = ds->latitude.udeg / 1000000.0;
- locationList.append(new MapLocation(ds->uuid, QGeoCoordinate(latitude, longitude)));
+ const qreal latitude = ds->latitude.udeg * 0.000001;
+ const qreal longitude = ds->longitude.udeg * 0.000001;
+ QGeoCoordinate dsCoord(latitude, longitude);
+ // check if there are no locations too close to the current dive site
+ bool diveSiteTooClose = false;
+ foreach(MapLocation *location, locationList) {
+ QGeoCoordinate coord = qvariant_cast<QGeoCoordinate>(location->getRole(MapLocation::Roles::RoleCoordinate));
+ if (dsCoord.distanceTo(coord) < MIN_DISTANCE_BETWEEN_DIVE_SITES_M) {
+ diveSiteTooClose = true;
+ break;
+ }
+ }
+ if (!diveSiteTooClose)
+ locationList.append(new MapLocation(ds->uuid, QGeoCoordinate(latitude, longitude)));
}
m_mapLocationModel->addList(locationList);
}