Fix latLon formatting in search

This commit is contained in:
max-klaus 2020-09-16 12:12:20 +03:00
parent 6173a2b4a6
commit a11dd191ae

View file

@ -33,6 +33,7 @@ import net.osmand.util.LocationParser.ParsedOpenLocationCode;
import net.osmand.util.MapUtils;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -1407,6 +1408,7 @@ public class SearchCoreFactory {
private LatLon olcPhraseLocation;
private ParsedOpenLocationCode cachedParsedCode;
private final List<String> citySubTypes = Arrays.asList("city", "town", "village");
private final DecimalFormat latLonFormatter = new DecimalFormat("#.0####");
public SearchLocationAndUrlAPI() {
super(ObjectType.LOCATION, ObjectType.PARTIAL_LOCATION);
@ -1498,7 +1500,7 @@ public class SearchCoreFactory {
sp.priority = SEARCH_LOCATION_PRIORITY;
sp.object = sp.location = ll;
sp.localeName = ((float) sp.location.getLatitude()) + ", <input> ";
sp.localeName = formatLatLon(sp.location.getLatitude()) + ", <input> ";
sp.objectType = ObjectType.PARTIAL_LOCATION;
resultMatcher.publish(sp);
}
@ -1510,7 +1512,7 @@ public class SearchCoreFactory {
SearchResult sp = new SearchResult(phrase);
sp.priority = SEARCH_LOCATION_PRIORITY;
sp.object = sp.location = l;
sp.localeName = ((float) sp.location.getLatitude()) + ", " + ((float) sp.location.getLongitude());
sp.localeName = formatLatLon(sp.location.getLatitude()) + ", " + formatLatLon(sp.location.getLongitude());
sp.objectType = ObjectType.LOCATION;
sp.wordsSpan = lw;
resultMatcher.publish(sp);
@ -1525,7 +1527,7 @@ public class SearchCoreFactory {
sp.object = pnt;
sp.wordsSpan = text;
sp.location = new LatLon(pnt.getLatitude(), pnt.getLongitude());
sp.localeName = ((float)pnt.getLatitude()) +", " + ((float) pnt.getLongitude());
sp.localeName = formatLatLon(pnt.getLatitude()) +", " + formatLatLon(pnt.getLongitude());
if (pnt.getZoom() > 0) {
sp.preferredZoom = pnt.getZoom();
}
@ -1555,6 +1557,10 @@ public class SearchCoreFactory {
}
return cachedParsedCode == null ? SEARCH_LOCATION_PRIORITY : SEARCH_MAX_PRIORITY;
}
private String formatLatLon(double latLon) {
return latLonFormatter.format(latLon);
}
}
private static String stripBraces(String localeName) {