diff --git a/OsmAnd-java/src/net/osmand/data/TransportStop.java b/OsmAnd-java/src/net/osmand/data/TransportStop.java index 9aa9f3d5fc..e08afc39b5 100644 --- a/OsmAnd-java/src/net/osmand/data/TransportStop.java +++ b/OsmAnd-java/src/net/osmand/data/TransportStop.java @@ -1,8 +1,9 @@ package net.osmand.data; public class TransportStop extends MapObject { - int[] referencesToRoutes = null; - + private int[] referencesToRoutes = null; + public int distance; + public TransportStop(){ } diff --git a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java index 448f1cd186..a3a5b1af09 100644 --- a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java @@ -50,6 +50,8 @@ import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -754,13 +756,20 @@ public class ContextMenuLayer extends OsmandMapLayer { List transportStops = findTransportStopsAt(latLon.getLatitude(), latLon.getLongitude()); List transportStopsReplacement = new ArrayList<>(); for (Amenity amenity : transportStopAmenities) { + List amenityTransportStops = new ArrayList<>(); for (TransportStop transportStop : transportStops) { if (transportStop.getName().startsWith(amenity.getName())) { - selectedObjects.remove(amenity); - if (!transportStopsReplacement.contains(transportStop)) { - transportStopsReplacement.add(transportStop); - } - break; + amenityTransportStops.add(transportStop); + } + } + if (amenityTransportStops.size() > 0) { + selectedObjects.remove(amenity); + if (amenityTransportStops.size() > 1) { + sort(amenity.getLocation(), amenityTransportStops); + } + TransportStop amenityTransportStop = amenityTransportStops.get(0); + if (!transportStopsReplacement.contains(amenityTransportStop)) { + transportStopsReplacement.add(amenityTransportStop); } } } @@ -776,6 +785,19 @@ public class ContextMenuLayer extends OsmandMapLayer { } } + private void sort(@NonNull LatLon latLon, List transportStops) { + for (TransportStop transportStop : transportStops) { + transportStop.distance = (int) MapUtils.getDistance(latLon, transportStop.getLocation()); + } + Collections.sort(transportStops, new Comparator() { + + @Override + public int compare(TransportStop s1, TransportStop s2) { + return Algorithms.compare(s1.distance, s2.distance); + } + }); + } + @NonNull private List findTransportStopsAt(double latitude, double longitude) { ArrayList transportStops = new ArrayList<>();