Show locations with same name on the map if they are more than 50m apart

Not showing them at all was a little too blunt of an instrument. There
likely are dive spots with the same name at different resorts. And even
at the same resort you could have multiple morings for the same dive
site.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2013-06-05 11:46:57 +09:00
parent 9dab886117
commit 6f979b48ed
2 changed files with 16 additions and 7 deletions

View file

@ -11,6 +11,7 @@
#include <marble/MarbleModel.h>
#include <marble/MarbleDirs.h>
#include <marble/MapThemeManager.h>
#include <marble/GeoDataLineString.h>
#if INCOMPLETE_MARBLE
#include "marble/GeoDataTreeModel.h"
#else
@ -69,19 +70,28 @@ void GlobeGPS::reload()
}
loadedDives = new GeoDataDocument;
QMap<QString, GeoDataPlacemark *> locationMap;
diveLocations.clear();
int idx = 0;
struct dive *dive;
for_each_dive(idx, dive) {
if (dive_has_gps_location(dive)) {
// don't add dive locations twice.
if (diveLocations.contains(QString(dive->location)))
continue;
diveLocations.append(QString(dive->location));
GeoDataPlacemark *place = new GeoDataPlacemark(dive->location);
place->setCoordinate(dive->longitude.udeg / 1000000.0,dive->latitude.udeg / 1000000.0 , 0, GeoDataCoordinates::Degree);
// don't add dive locations twice, unless they are at least 50m apart
if (locationMap[QString(dive->location)]) {
GeoDataPoint existingLocation = locationMap[QString(dive->location)]->coordinate();
GeoDataLineString segment = GeoDataLineString();
segment.append(existingLocation);
GeoDataPoint newLocation = place->coordinate();
segment.append(newLocation);
double dist = segment.length(6371);
// the dist is scaled to the radius given - so with 6371km as radius
// 50m turns into 0.05 as threashold
if (dist < 0.05)
continue;
}
locationMap[QString(dive->location)] = place;
loadedDives->append(place);
}
}

View file

@ -26,7 +26,6 @@ protected:
private:
GeoDataDocument *loadedDives;
QStringList diveLocations;
struct dive* editingDiveCoords;
KMessageWidget* messageWidget;