diff --git a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java index a4916d4187..360fafbdf9 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java @@ -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 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()) + ", "; + sp.localeName = formatLatLon(sp.location.getLatitude()) + ", "; 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) {