From 3f7a4ea568079fe54fab1533a8e90eddf295c4ff Mon Sep 17 00:00:00 2001 From: Jan Backhaus Date: Fri, 30 Oct 2020 15:27:08 +0100 Subject: [PATCH] Fixed MGRS decoding when still containing spaces. --- .../java/com/jwetherell/openmap/common/MGRSPoint.java | 9 +++++++++ .../src/main/java/net/osmand/util/LocationParser.java | 6 +----- .../plus/search/QuickSearchCoordinatesFragment.java | 4 ++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/OsmAnd-java/src/main/java/com/jwetherell/openmap/common/MGRSPoint.java b/OsmAnd-java/src/main/java/com/jwetherell/openmap/common/MGRSPoint.java index a39c5af336..6e99eec8b5 100644 --- a/OsmAnd-java/src/main/java/com/jwetherell/openmap/common/MGRSPoint.java +++ b/OsmAnd-java/src/main/java/com/jwetherell/openmap/common/MGRSPoint.java @@ -108,6 +108,15 @@ public class MGRSPoint extends ZonedUTMPoint { * an UPPERCASE coordinate string is expected. */ protected void decode(String mgrsString) throws NumberFormatException { + if (mgrsString.contains(" ")) { + String[] parts = mgrsString.split(" "); + StringBuilder s = new StringBuilder(); + for (String i : parts) { + s.append(i); + } + mgrsString = s.toString(); + } + if (mgrsString == null || mgrsString.length() == 0) { throw new NumberFormatException("MGRSPoint coverting from nothing"); } diff --git a/OsmAnd-java/src/main/java/net/osmand/util/LocationParser.java b/OsmAnd-java/src/main/java/net/osmand/util/LocationParser.java index 9e54bea347..efa4cdaf42 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/LocationParser.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/LocationParser.java @@ -140,11 +140,7 @@ public class LocationParser { //detect MGRS if (all.size() >= 3 && (d.size() == 2 || d.size() == 3) && all.get(1) instanceof String) { try { - StringBuilder s = new StringBuilder(); - for (String i : strings) { - s.append(i); - } - MGRSPoint mgrsPoint = new MGRSPoint(s.toString()); + MGRSPoint mgrsPoint = new MGRSPoint(locPhrase); LatLonPoint ll = mgrsPoint.toLatLonPoint(); return validateAndCreateLatLon(ll.getLatitude(), ll.getLongitude()); } catch (NumberFormatException e) { diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchCoordinatesFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchCoordinatesFragment.java index 409f38b319..78383f3179 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchCoordinatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchCoordinatesFragment.java @@ -610,6 +610,10 @@ public class QuickSearchCoordinatesFragment extends DialogFragment implements Os if (latLon != null) { MGRSPoint pnt = new MGRSPoint(new LatLonPoint(latLon.getLatitude(), latLon.getLongitude())); mgrsEdit.setText(pnt.toFlavoredString(5)); + } else if (prevFormat == PointDescription.UTM_FORMAT) { + mgrsEdit.setText(zoneEdit.getText()); + } else if (prevFormat == PointDescription.OLC_FORMAT) { + mgrsEdit.setText(olcEdit.getText()); } else { mgrsEdit.setText(latEdit.getText());