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>
This commit is contained in:
Lubomir I. Ivanov 2017-07-24 02:49:11 +03:00 committed by Dirk Hohndel
parent 66b2f0c88c
commit 4b8b61100a

View file

@ -9,6 +9,8 @@
#include "core/divesite.h" #include "core/divesite.h"
#include "qt-models/maplocationmodel.h" #include "qt-models/maplocationmodel.h"
#define MIN_DISTANCE_BETWEEN_DIVE_SITES_M 50.0
MapWidgetHelper::MapWidgetHelper(QObject *parent) : QObject(parent) MapWidgetHelper::MapWidgetHelper(QObject *parent) : QObject(parent)
{ {
m_mapLocationModel = new MapLocationModel(this); m_mapLocationModel = new MapLocationModel(this);
@ -36,9 +38,20 @@ void MapWidgetHelper::reloadMapLocations()
for_each_dive_site(idx, ds) { for_each_dive_site(idx, ds) {
if (!dive_site_has_gps_location(ds)) if (!dive_site_has_gps_location(ds))
continue; continue;
const qreal longitude = ds->longitude.udeg / 1000000.0; const qreal latitude = ds->latitude.udeg * 0.000001;
const qreal latitude = ds->latitude.udeg / 1000000.0; const qreal longitude = ds->longitude.udeg * 0.000001;
locationList.append(new MapLocation(ds->uuid, QGeoCoordinate(latitude, longitude))); 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); m_mapLocationModel->addList(locationList);
} }