Fixed MGRS decoding when still containing spaces.

This commit is contained in:
Jan Backhaus 2020-10-30 15:27:08 +01:00
parent 436630c1e2
commit 3f7a4ea568
3 changed files with 14 additions and 5 deletions

View file

@ -108,6 +108,15 @@ public class MGRSPoint extends ZonedUTMPoint {
* an UPPERCASE coordinate string is expected. * an UPPERCASE coordinate string is expected.
*/ */
protected void decode(String mgrsString) throws NumberFormatException { 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) { if (mgrsString == null || mgrsString.length() == 0) {
throw new NumberFormatException("MGRSPoint coverting from nothing"); throw new NumberFormatException("MGRSPoint coverting from nothing");
} }

View file

@ -140,11 +140,7 @@ public class LocationParser {
//detect MGRS //detect MGRS
if (all.size() >= 3 && (d.size() == 2 || d.size() == 3) && all.get(1) instanceof String) { if (all.size() >= 3 && (d.size() == 2 || d.size() == 3) && all.get(1) instanceof String) {
try { try {
StringBuilder s = new StringBuilder(); MGRSPoint mgrsPoint = new MGRSPoint(locPhrase);
for (String i : strings) {
s.append(i);
}
MGRSPoint mgrsPoint = new MGRSPoint(s.toString());
LatLonPoint ll = mgrsPoint.toLatLonPoint(); LatLonPoint ll = mgrsPoint.toLatLonPoint();
return validateAndCreateLatLon(ll.getLatitude(), ll.getLongitude()); return validateAndCreateLatLon(ll.getLatitude(), ll.getLongitude());
} catch (NumberFormatException e) { } catch (NumberFormatException e) {

View file

@ -610,6 +610,10 @@ public class QuickSearchCoordinatesFragment extends DialogFragment implements Os
if (latLon != null) { if (latLon != null) {
MGRSPoint pnt = new MGRSPoint(new LatLonPoint(latLon.getLatitude(), latLon.getLongitude())); MGRSPoint pnt = new MGRSPoint(new LatLonPoint(latLon.getLatitude(), latLon.getLongitude()));
mgrsEdit.setText(pnt.toFlavoredString(5)); 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 { } else {
mgrsEdit.setText(latEdit.getText()); mgrsEdit.setText(latEdit.getText());