diff --git a/OsmAnd-java/src/main/java/net/osmand/data/DataTileManager.java b/OsmAnd-java/src/main/java/net/osmand/data/DataTileManager.java index 6a72bf16c8..ca76753bfa 100644 --- a/OsmAnd-java/src/main/java/net/osmand/data/DataTileManager.java +++ b/OsmAnd-java/src/main/java/net/osmand/data/DataTileManager.java @@ -65,6 +65,14 @@ public class DataTileManager { int tileXDown = (int) MapUtils.getTileNumberX(zoom, longitudeDown) + 1; int tileYDown = (int) MapUtils.getTileNumberY(zoom, latitudeDown) + 1; List result = new ArrayList(); + if(tileXUp > tileXDown) { + tileXDown = tileXUp; + tileXUp = 0; + } + if(tileYUp > tileYDown) { + tileYDown = tileYUp; + tileXUp = 0; + } for (int i = tileXUp; i <= tileXDown; i++) { for (int j = tileYUp; j <= tileYDown; j++) { putObjects(i, j, result); diff --git a/OsmAnd-java/src/main/java/net/osmand/util/MapUtils.java b/OsmAnd-java/src/main/java/net/osmand/util/MapUtils.java index 7c83cb8f89..b11575eaa5 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/MapUtils.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/MapUtils.java @@ -55,6 +55,21 @@ public class MapUtils { // Scalar multiplication between (AB, AC) return (xB - xA) * (xC - xA) + (yB - yA) * (yC - yA); } + + public static LatLon calculateMidPoint(LatLon s1, LatLon s2) { + double lat1 = s1.getLatitude() / 180 * Math.PI; + double lon1 = s1.getLongitude() / 180 * Math.PI; + double lat2 = s2.getLatitude() / 180 * Math.PI; + double lon2 = s2.getLongitude() / 180 * Math.PI; + double Bx = Math.cos(lat2) * Math.cos(lon2 - lon1); + double By = Math.cos(lat2) * Math.sin(lon2 - lon1); + double latMid = Math.atan2(Math.sin(lat1) + Math.sin(lat2), + Math.sqrt((Math.cos(lat1) + Bx) * (Math.cos(lat1) + Bx) + By * By)); + double lonMid = lon1 + Math.atan2(By, Math.cos(lat1) + Bx); + LatLon m = new LatLon(MapUtils.checkLatitude(latMid * 180 / Math.PI), + MapUtils.checkLongitude(lonMid * 180 / Math.PI)); + return m; + } public static double getOrthogonalDistance(double lat, double lon, double fromLat, double fromLon, double toLat, double toLon) { return getDistance(getProjection(lat, lon, fromLat, fromLon, toLat, toLon), lat, lon);