diff --git a/OsmAnd/src/net/osmand/plus/views/layers/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/ContextMenuLayer.java index ad8f68ee83..f4e5b18a2d 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/ContextMenuLayer.java @@ -574,11 +574,21 @@ public class ContextMenuLayer extends OsmandMapLayer { applyingMarkerLatLon = null; } + public boolean showContextMenuForMyLocation() { + PointLocationLayer provider = view.getLayerByClass(PointLocationLayer.class); + if (provider != null) { + LatLon ll = provider.getObjectLocation(null); + if (ll != null) { + PointDescription pointDescription = provider.getObjectName(null); + return showContextMenu(ll, pointDescription, ll, provider); + } + } + return false; + } + public boolean showContextMenu(double latitude, double longitude, boolean showUnknownLocation) { - RotatedTileBox cp = activity.getMapView().getCurrentRotatedTileBox(); - float x = cp.getPixXFromLatLon(latitude, longitude); - float y = cp.getPixYFromLatLon(latitude, longitude); - return showContextMenu(new PointF(x, y), activity.getMapView().getCurrentRotatedTileBox(), showUnknownLocation); + return showContextMenu(getPointFromLatLon(latitude, longitude), + activity.getMapView().getCurrentRotatedTileBox(), showUnknownLocation); } public boolean showContextMenu(@NonNull LatLon latLon, @@ -803,6 +813,13 @@ public class ContextMenuLayer extends OsmandMapLayer { return false; } + private PointF getPointFromLatLon(double latitude, double longitude) { + RotatedTileBox cp = activity.getMapView().getCurrentRotatedTileBox(); + float x = cp.getPixXFromLatLon(latitude, longitude); + float y = cp.getPixYFromLatLon(latitude, longitude); + return new PointF(x, y); + } + private List getValues(@Nullable QStringStringHash set) { List res = new ArrayList<>(); if (set != null) { diff --git a/OsmAnd/src/net/osmand/plus/views/layers/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/MapControlsLayer.java index e6ce1ce4f1..cd6bf62ced 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/MapControlsLayer.java @@ -439,15 +439,9 @@ public class MapControlsLayer extends OsmandMapLayer { } private void showContextMenuForMyLocation() { - OsmAndLocationProvider lp = app.getLocationProvider(); - Location lastKnownLocation = lp.getLastKnownLocation(); - Location lastStaleKnownLocation = lp.getLastStaleKnownLocation(); - Location location = lastKnownLocation != null ? lastKnownLocation : lastStaleKnownLocation; - if (location != null) { - ContextMenuLayer cml = mapActivity.getMapView().getLayerByClass(ContextMenuLayer.class); - if (cml != null) { - cml.showContextMenu(location.getLatitude(), location.getLongitude(), true); - } + ContextMenuLayer cml = mapActivity.getMapView().getLayerByClass(ContextMenuLayer.class); + if (cml != null) { + cml.showContextMenuForMyLocation(); } }