From c21c8ad903d3609bef8d9d1a09026607529ff314 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Mon, 8 Aug 2016 15:49:10 +0300 Subject: [PATCH] Fix geocoding crash --- .../osmand/plus/CurrentPositionHelper.java | 64 +++++++++++-------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java b/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java index 9b9bfcf90a..3cdb89868c 100644 --- a/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java +++ b/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java @@ -77,7 +77,7 @@ public class CurrentPositionHelper implements ResourceListener { protected Void doInBackground(Void... params) { try { processGeocoding(loc, geoCoding, storeFound, result); - } catch (IOException e) { + } catch (Exception e) { e.printStackTrace(); } return null; @@ -111,41 +111,44 @@ public class CurrentPositionHelper implements ResourceListener { protected void justifyResult(List res, final ResultMatcher result) { List complete = new ArrayList<>(); double minBuildingDistance = 0; - for (GeocodingResult r : res) { - Collection rar = app.getResourceManager().getAddressRepositories(); - RegionAddressRepository foundRepo = null; - for (RegionAddressRepository repo : rar) { - BinaryMapIndexReader reader = repo.getFile(); - for (RouteRegion rb : reader.getRoutingIndexes()) { - if (r.regionFP == rb.getFilePointer() && r.regionLen == rb.getLength()) { - foundRepo = repo; - break; + if (res != null) { + for (GeocodingResult r : res) { + Collection rar = app.getResourceManager().getAddressRepositories(); + RegionAddressRepository foundRepo = null; + for (RegionAddressRepository repo : rar) { + BinaryMapIndexReader reader = repo.getFile(); + for (RouteRegion rb : reader.getRoutingIndexes()) { + if (r.regionFP == rb.getFilePointer() && r.regionLen == rb.getLength()) { + foundRepo = repo; + break; + } + if (result.isCancelled()) { + break; + } } - if (result.isCancelled()) { + if (foundRepo != null || result.isCancelled()) { break; } } - if (foundRepo != null || result.isCancelled()) { + if (result.isCancelled()) { break; - } - } - if (result.isCancelled()) { - break; - } else if (foundRepo != null) { - List justified = foundRepo.justifyReverseGeocodingSearch(r, minBuildingDistance, result); - if (!justified.isEmpty()) { - double md = justified.get(0).getDistance(); - if (minBuildingDistance == 0) { - minBuildingDistance = md; - } else { - minBuildingDistance = Math.min(md, minBuildingDistance); + } else if (foundRepo != null) { + List justified = foundRepo.justifyReverseGeocodingSearch(r, minBuildingDistance, result); + if (!justified.isEmpty()) { + double md = justified.get(0).getDistance(); + if (minBuildingDistance == 0) { + minBuildingDistance = md; + } else { + minBuildingDistance = Math.min(md, minBuildingDistance); + } + complete.addAll(justified); } - complete.addAll(justified); + } else { + complete.add(r); } - } else { - complete.add(r); } } + if (result.isCancelled()) { app.runInUIThread(new Runnable() { public void run() { @@ -225,7 +228,12 @@ public class CurrentPositionHelper implements ResourceListener { return null; } } - return new GeocodingUtilities().reverseGeocodingSearch(geocoding ? defCtx : ctx, lat, lon); + try { + return new GeocodingUtilities().reverseGeocodingSearch(geocoding ? defCtx : ctx, lat, lon); + } catch (Exception e) { + e.printStackTrace(); + return null; + } } @Override