From ee99146c97fce2c6f1aebc346e8f6d7b47bc33eb Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Mon, 23 Mar 2020 19:59:26 +0100 Subject: [PATCH] GeocoderThread: Prefer parsing address from individual fields. --- .../de/schildbach/oeffi/util/GeocoderThread.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/oeffi/src/de/schildbach/oeffi/util/GeocoderThread.java b/oeffi/src/de/schildbach/oeffi/util/GeocoderThread.java index 9df5324..cb068fa 100644 --- a/oeffi/src/de/schildbach/oeffi/util/GeocoderThread.java +++ b/oeffi/src/de/schildbach/oeffi/util/GeocoderThread.java @@ -114,16 +114,18 @@ public class GeocoderThread extends Thread { else coord = null; - final Location location; final int maxAddressLineIndex = address.getMaxAddressLineIndex(); - if (maxAddressLineIndex >= 2 && Strings.emptyToNull(address.getAddressLine(2)) != null) { - location = new Location(LocationType.ADDRESS, null, coord, address.getAddressLine(1), - address.getAddressLine(0)); - } else if (address.getThoroughfare() != null) { + final Location location; + if (Strings.emptyToNull(address.getFeatureName()) != null && Strings.emptyToNull(address.getLocality()) != null + && Strings.emptyToNull(address.getPostalCode()) != null) { final Joiner joiner = Joiner.on(' ').skipNulls(); + final String thoroughfare = Strings.emptyToNull(address.getThoroughfare()); location = new Location(LocationType.ADDRESS, null, coord, joiner.join(address.getPostalCode(), address.getLocality()), - joiner.join(address.getThoroughfare(), address.getFeatureName())); + joiner.join(thoroughfare, address.getFeatureName())); + } else if (maxAddressLineIndex >= 2 && Strings.emptyToNull(address.getAddressLine(2)) != null) { + location = new Location(LocationType.ADDRESS, null, coord, address.getAddressLine(1), + address.getAddressLine(0)); } else { location = new Location(LocationType.ADDRESS, null, coord); }