@Test public void testGetBoundingBox() { BoundingBoxCalculator cal = new BoundingBoxCalculator(); GpsPoint center = new GpsPoint(47.21806, -1.55278); double bboxsize = 3 * 1000; double tolerance = 1.5d * bboxsize / 1000; BoundingBox bbox = cal.getBoundingBox(center, bboxsize); assertNotNull(bbox); AsTheCrowFliesDistanceCalculator distanceCalc = new AsTheCrowFliesDistanceCalculator(); GpsPoint bottomright = new GpsPoint(bbox.getMin().getLatitude(), bbox .getMax().getLongitude()); GpsPoint topright = new GpsPoint(bbox.getMax().getLatitude(), bbox .getMax().getLongitude()); GpsPoint bottomleft = new GpsPoint(bbox.getMin().getLatitude(), bbox .getMin().getLongitude()); double distanceLat = distanceCalc.getDistanceBetweenPoints(bottomright, topright); assertEquals(bboxsize * 2, distanceLat, tolerance); double distanceLong = distanceCalc.getDistanceBetweenPoints( bottomright, bottomleft); assertEquals(bboxsize * 2, distanceLong, tolerance); }
public BoundingBox getBoundingBox(GpsPoint center, double distance) { double radDist = distance / EARTH_RADIUS; double radLat = Math.toRadians(center.getLatitude()); double radLon = Math.toRadians(center.getLongitude()); double minLat = radLat - radDist; double maxLat = radLat + radDist; double minLon, maxLon; if (minLat > MIN_LATITUDE && maxLat < MAX_LATITUDE) { double deltaLon = Math.asin(Math.sin(radDist) / Math.cos(radLat)); minLon = radLon - deltaLon; if (minLon < MIN_LONGITUDE) { minLon += 2d * Math.PI; } maxLon = radLon + deltaLon; if (maxLon > MAX_LONGITUDE) { maxLon -= 2d * Math.PI; } } else { minLat = Math.max(minLat, MIN_LATITUDE); maxLat = Math.min(maxLat, MAX_LATITUDE); minLon = MIN_LONGITUDE; maxLon = MAX_LONGITUDE; } GpsPoint min = new GpsPoint(Math.toDegrees(minLat), Math.toDegrees(minLon)); GpsPoint max = new GpsPoint(Math.toDegrees(maxLat), Math.toDegrees(maxLon)); return new BoundingBox(min, max); }
BoundingBoxCalculator { public BoundingBox getBoundingBox(GpsPoint center, double distance) { double radDist = distance / EARTH_RADIUS; double radLat = Math.toRadians(center.getLatitude()); double radLon = Math.toRadians(center.getLongitude()); double minLat = radLat - radDist; double maxLat = radLat + radDist; double minLon, maxLon; if (minLat > MIN_LATITUDE && maxLat < MAX_LATITUDE) { double deltaLon = Math.asin(Math.sin(radDist) / Math.cos(radLat)); minLon = radLon - deltaLon; if (minLon < MIN_LONGITUDE) { minLon += 2d * Math.PI; } maxLon = radLon + deltaLon; if (maxLon > MAX_LONGITUDE) { maxLon -= 2d * Math.PI; } } else { minLat = Math.max(minLat, MIN_LATITUDE); maxLat = Math.min(maxLat, MAX_LATITUDE); minLon = MIN_LONGITUDE; maxLon = MAX_LONGITUDE; } GpsPoint min = new GpsPoint(Math.toDegrees(minLat), Math.toDegrees(minLon)); GpsPoint max = new GpsPoint(Math.toDegrees(maxLat), Math.toDegrees(maxLon)); return new BoundingBox(min, max); } }
BoundingBoxCalculator { public BoundingBox getBoundingBox(GpsPoint center, double distance) { double radDist = distance / EARTH_RADIUS; double radLat = Math.toRadians(center.getLatitude()); double radLon = Math.toRadians(center.getLongitude()); double minLat = radLat - radDist; double maxLat = radLat + radDist; double minLon, maxLon; if (minLat > MIN_LATITUDE && maxLat < MAX_LATITUDE) { double deltaLon = Math.asin(Math.sin(radDist) / Math.cos(radLat)); minLon = radLon - deltaLon; if (minLon < MIN_LONGITUDE) { minLon += 2d * Math.PI; } maxLon = radLon + deltaLon; if (maxLon > MAX_LONGITUDE) { maxLon -= 2d * Math.PI; } } else { minLat = Math.max(minLat, MIN_LATITUDE); maxLat = Math.min(maxLat, MAX_LATITUDE); minLon = MIN_LONGITUDE; maxLon = MAX_LONGITUDE; } GpsPoint min = new GpsPoint(Math.toDegrees(minLat), Math.toDegrees(minLon)); GpsPoint max = new GpsPoint(Math.toDegrees(maxLat), Math.toDegrees(maxLon)); return new BoundingBox(min, max); }  }
BoundingBoxCalculator { public BoundingBox getBoundingBox(GpsPoint center, double distance) { double radDist = distance / EARTH_RADIUS; double radLat = Math.toRadians(center.getLatitude()); double radLon = Math.toRadians(center.getLongitude()); double minLat = radLat - radDist; double maxLat = radLat + radDist; double minLon, maxLon; if (minLat > MIN_LATITUDE && maxLat < MAX_LATITUDE) { double deltaLon = Math.asin(Math.sin(radDist) / Math.cos(radLat)); minLon = radLon - deltaLon; if (minLon < MIN_LONGITUDE) { minLon += 2d * Math.PI; } maxLon = radLon + deltaLon; if (maxLon > MAX_LONGITUDE) { maxLon -= 2d * Math.PI; } } else { minLat = Math.max(minLat, MIN_LATITUDE); maxLat = Math.min(maxLat, MAX_LATITUDE); minLon = MIN_LONGITUDE; maxLon = MAX_LONGITUDE; } GpsPoint min = new GpsPoint(Math.toDegrees(minLat), Math.toDegrees(minLon)); GpsPoint max = new GpsPoint(Math.toDegrees(maxLat), Math.toDegrees(maxLon)); return new BoundingBox(min, max); }  BoundingBox getBoundingBox(GpsPoint center, double distance); }
BoundingBoxCalculator { public BoundingBox getBoundingBox(GpsPoint center, double distance) { double radDist = distance / EARTH_RADIUS; double radLat = Math.toRadians(center.getLatitude()); double radLon = Math.toRadians(center.getLongitude()); double minLat = radLat - radDist; double maxLat = radLat + radDist; double minLon, maxLon; if (minLat > MIN_LATITUDE && maxLat < MAX_LATITUDE) { double deltaLon = Math.asin(Math.sin(radDist) / Math.cos(radLat)); minLon = radLon - deltaLon; if (minLon < MIN_LONGITUDE) { minLon += 2d * Math.PI; } maxLon = radLon + deltaLon; if (maxLon > MAX_LONGITUDE) { maxLon -= 2d * Math.PI; } } else { minLat = Math.max(minLat, MIN_LATITUDE); maxLat = Math.min(maxLat, MAX_LATITUDE); minLon = MIN_LONGITUDE; maxLon = MAX_LONGITUDE; } GpsPoint min = new GpsPoint(Math.toDegrees(minLat), Math.toDegrees(minLon)); GpsPoint max = new GpsPoint(Math.toDegrees(maxLat), Math.toDegrees(maxLon)); return new BoundingBox(min, max); }  BoundingBox getBoundingBox(GpsPoint center, double distance);  }