[Bug #2934] Geo Lookup - support for remote dive sites

Some remote dive sites have no populated places (towns, cities)
nearby. For such sites, we now fall back to looking up
unpopulated place names, such as the reef or island name.

Also some code refactorisation:
the actual network access is now encapsulated in its own
function removing some duplicated code handling in the
reverseGeoLookup function and making it more readable.

Furthermore, reverseGeoLookup() was completely refactored as
most of its functionality was due to legacy requirements; the
current code-base only calls this function from a single
location and only with an empty taxonomy_data object. This
makes the function more focussed and much simpler and more
readable.

Finally, a resource leak in reverseGeocde introduced in
4f3b26f9b6 was fixed.

Signed-off-by: Michael Werle <micha@michaelwerle.com>
This commit is contained in:
Michael Werle 2020-09-03 12:04:05 +09:00 committed by bstoeger
parent 4f3b26f9b6
commit d404aa767f
5 changed files with 100 additions and 124 deletions

View file

@ -317,10 +317,12 @@ void LocationInformationWidget::reverseGeocode()
location_t location = parseGpsText(ui.diveSiteCoordinates->text());
if (!ds || !has_location(&location))
return;
taxonomy_data taxonomy = { 0, 0 };
reverseGeoLookup(location.lat, location.lon, &taxonomy);
if (ds != diveSite)
taxonomy_data taxonomy = reverseGeoLookup(location.lat, location.lon);
if (ds != diveSite) {
free_taxonomy(&taxonomy);
return;
}
// This call transfers ownership of the taxonomy memory into an EditDiveSiteTaxonomy object
Command::editDiveSiteTaxonomy(ds, taxonomy);
}