From 653c5afad1b453d228b1ca8934c373a37d5c4df9 Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Fri, 21 Dec 2018 19:21:02 +0100 Subject: [PATCH] DirectionsShortcutActivity: Use LocationView.addressToLocation() for parsing Geocoder results too. --- .../DirectionsShortcutActivity.java | 38 +++---------------- 1 file changed, 6 insertions(+), 32 deletions(-) diff --git a/oeffi/src/de/schildbach/oeffi/directions/DirectionsShortcutActivity.java b/oeffi/src/de/schildbach/oeffi/directions/DirectionsShortcutActivity.java index 6da8998..239fe29 100644 --- a/oeffi/src/de/schildbach/oeffi/directions/DirectionsShortcutActivity.java +++ b/oeffi/src/de/schildbach/oeffi/directions/DirectionsShortcutActivity.java @@ -17,7 +17,6 @@ package de.schildbach.oeffi.directions; -import java.util.Locale; import java.util.Set; import javax.net.ssl.SSLException; @@ -169,44 +168,19 @@ public class DirectionsShortcutActivity extends OeffiActivity public void onLocation(final Point here) { new GeocoderThread(DirectionsShortcutActivity.this, here, new GeocoderThread.Callback() { public void onGeocoderResult(final Address address) { - final String resolved = extractAddress(address); - if (resolved != null) - query(here, resolved); - else - query(here); + final Location location = LocationView.addressToLocation(address); + query(location); } public void onGeocoderFail(final Exception exception) { - query(here); - } - - private String extractAddress(final Address address) { - final int maxAddressLineIndex = address.getMaxAddressLineIndex(); - if (maxAddressLineIndex < 0) - return null; - - final StringBuilder builder = new StringBuilder(); - for (int i = 0; i <= maxAddressLineIndex; i++) { - builder.append(address.getAddressLine(i)); - builder.append(", "); - } - builder.setLength(builder.length() - 2); - - return builder.toString(); + final Location location = Location + .coord(Point.fromDouble(here.getLatAsDouble(), here.getLonAsDouble())); + query(location); } }); } - private void query(final Point here) { - final String hereName = String.format(Locale.ENGLISH, "%.6f, %.6f", here.getLatAsDouble(), - here.getLonAsDouble()); - - query(here, hereName); - } - - private void query(final Point here, final String hereName) { - final Location from = new Location(LocationType.ADDRESS, null, here, null, hereName); - + private void query(final Location from) { final Intent intent = getIntent(); final NetworkProvider networkProvider = getNetworkExtra(intent);