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.
*/
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");
}

View file

@ -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) {

View file

@ -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());