From dcc3c09d75c1e291b8758067ad946f7542d05654 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Mon, 21 Sep 2020 17:07:05 +0300 Subject: [PATCH] Fix geocoding --- .../net/osmand/binary/GeocodingUtilities.java | 14 ++++---- .../osmand/plus/CurrentPositionHelper.java | 33 ++++++++++++++++--- 2 files changed, 36 insertions(+), 11 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 77357bac9b..a372f12aa1 100644 --- a/OsmAnd-java/src/main/java/net/osmand/binary/GeocodingUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/binary/GeocodingUtilities.java @@ -334,14 +334,16 @@ public class GeocodingUtilities { boolean eqStreet = Algorithms.stringsEqual(gr1.streetName, gr2.streetName); if (eqStreet) { boolean sameObj = false; - if (gr1.building != null && gr2.building != null) { - if (Algorithms.stringsEqual(gr1.building.getName(), gr2.building.getName())) { - // same building + if (gr1.city != null && gr2.city != null) { + if (gr1.building != null && gr2.building != null) { + if (Algorithms.stringsEqual(gr1.building.getName(), gr2.building.getName())) { + // same building + sameObj = true; + } + } else if (gr1.building == null && gr2.building == null) { + // same street sameObj = true; } - } else if (gr1.building == null && gr2.building == null) { - // same street - sameObj = true; } if (sameObj) { double cityDist1 = MapUtils.getDistance(gr1.searchPoint, gr1.city.getLocation()); diff --git a/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java b/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java index a50a345aa3..cbbd36162f 100644 --- a/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java +++ b/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java @@ -25,7 +25,6 @@ import org.apache.commons.logging.Log; import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.concurrent.ExecutorService; @@ -154,7 +153,7 @@ public class CurrentPositionHelper { // single synchronized method private synchronized void processGeocoding(@NonNull Location loc, - @Nullable ResultMatcher geoCoding, + @Nullable final ResultMatcher geoCoding, boolean storeFound, boolean allowEmptyNames, @Nullable final ResultMatcher result, @@ -164,6 +163,21 @@ public class CurrentPositionHelper { boolean cancelPreviousSearch) { if (cancelPreviousSearch && request != requestNumber.get()) { + if (geoCoding != null) { + app.runInUIThread(new Runnable() { + @Override + public void run() { + geoCoding.publish(null); + } + }); + } else if (result != null) { + app.runInUIThread(new Runnable() { + @Override + public void run() { + result.publish(null); + } + }); + } return; } @@ -172,9 +186,18 @@ public class CurrentPositionHelper { if (storeFound) { lastAskedLocation = loc; lastFound = gr == null || gr.isEmpty() ? null : gr.get(0).point.getRoad(); - } else if(geoCoding != null) { - justifyResult(gr, geoCoding); - } else if(result != null) { + } else if (geoCoding != null) { + try { + justifyResult(gr, geoCoding); + } catch (Exception e) { + app.runInUIThread(new Runnable() { + @Override + public void run() { + geoCoding.publish(null); + } + }); + } + } else if (result != null) { app.runInUIThread(new Runnable() { @Override public void run() {