From 27bd894e56a9cb3a2d9a60d7c196db826b3a6e72 Mon Sep 17 00:00:00 2001 From: ivanPyrohivskyi Date: Mon, 15 Mar 2021 17:34:17 +0200 Subject: [PATCH 1/2] Fix reverse geocoding for building only --- .../main/java/net/osmand/binary/GeocodingUtilities.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/binary/GeocodingUtilities.java b/OsmAnd-java/src/main/java/net/osmand/binary/GeocodingUtilities.java index a372f12aa1..934672c95b 100644 --- a/OsmAnd-java/src/main/java/net/osmand/binary/GeocodingUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/binary/GeocodingUtilities.java @@ -282,10 +282,12 @@ public class GeocodingUtilities { } else { Collections.sort(streetsList, DISTANCE_COMPARATOR); double streetDistance = 0; + boolean isBuildingFound = knownMinBuildingDistance > 0; for (GeocodingResult street : streetsList) { - if (streetDistance == 0) { + boolean skipStreet = streetDistance > 0 && street.getDistance() > streetDistance + DISTANCE_STREET_FROM_CLOSEST_WITH_SAME_NAME; + if (streetDistance == 0 || !isBuildingFound) { streetDistance = street.getDistance(); - } else if (street.getDistance() > streetDistance + DISTANCE_STREET_FROM_CLOSEST_WITH_SAME_NAME) { + } else if (skipStreet) { continue; } street.connectionPoint = road.connectionPoint; @@ -307,6 +309,9 @@ public class GeocodingUtilities { res.add(nextBld); } } + if (skipStreet) { + continue; + } res.add(street); } } From 98a0829d5a4095aa4d87cbed0352c721270d4fec Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 15 Mar 2021 16:57:47 +0100 Subject: [PATCH 2/2] Small code improvement --- .../java/net/osmand/binary/GeocodingUtilities.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/binary/GeocodingUtilities.java b/OsmAnd-java/src/main/java/net/osmand/binary/GeocodingUtilities.java index 934672c95b..02f9e88098 100644 --- a/OsmAnd-java/src/main/java/net/osmand/binary/GeocodingUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/binary/GeocodingUtilities.java @@ -284,10 +284,10 @@ public class GeocodingUtilities { double streetDistance = 0; boolean isBuildingFound = knownMinBuildingDistance > 0; for (GeocodingResult street : streetsList) { - boolean skipStreet = streetDistance > 0 && street.getDistance() > streetDistance + DISTANCE_STREET_FROM_CLOSEST_WITH_SAME_NAME; - if (streetDistance == 0 || !isBuildingFound) { + if (streetDistance == 0) { streetDistance = street.getDistance(); - } else if (skipStreet) { + } else if (streetDistance > 0 && street.getDistance() > streetDistance + DISTANCE_STREET_FROM_CLOSEST_WITH_SAME_NAME && + isBuildingFound) { continue; } street.connectionPoint = road.connectionPoint; @@ -298,6 +298,7 @@ public class GeocodingUtilities { if (knownMinBuildingDistance == 0) { GeocodingResult firstBld = it.next(); knownMinBuildingDistance = firstBld.getDistance(); + isBuildingFound = true; res.add(firstBld); } while (it.hasNext()) { @@ -309,9 +310,6 @@ public class GeocodingUtilities { res.add(nextBld); } } - if (skipStreet) { - continue; - } res.add(street); } }