Rectangle boundingBox = Rectangle.fromBoundingCircle( center, radius ); double lowerLeftLatitude = boundingBox.getLowerLeft().getLatitude(); double lowerLeftLongitude = boundingBox.getLowerLeft().getLongitude(); double upperRightLatitude = boundingBox.getUpperRight().getLatitude(); double upperRightLongitude = boundingBox.getUpperRight().getLongitude();
return new Rectangle( Point.fromDegreesInclusive( minimumLatitude, minimumLongitude ), Point.fromDegreesInclusive( maximumLatitude, maximumLongitude )
return new Rectangle( Point.fromDegreesInclusive( minimumLatitude, minimumLongitude ), Point.fromDegreesInclusive( maximumLatitude, maximumLongitude )
Rectangle boundingBox = Rectangle.fromBoundingCircle( center, radius ); double lowerLeftLatitude = boundingBox.getLowerLeft().getLatitude(); double lowerLeftLongitude = boundingBox.getLowerLeft().getLongitude(); double upperRightLatitude = boundingBox.getUpperRight().getLatitude(); double upperRightLongitude = boundingBox.getUpperRight().getLongitude();
Rectangle boundingBox = Rectangle.fromBoundingCircle( center, radius ); latitudeFieldName, boundingBox.getLowerLeft().getLatitude(), boundingBox.getUpperRight().getLatitude(), true, true ); if ( boundingBox.getLowerLeft().getLongitude() <= boundingBox.getUpperRight().getLongitude() ) { longQuery = NumericRangeQuery.newDoubleRange( longitudeFieldName, boundingBox.getLowerLeft().getLongitude(), boundingBox.getUpperRight().getLongitude(), true, true ); .add( NumericRangeQuery.newDoubleRange( longitudeFieldName, boundingBox.getLowerLeft().getLongitude(), 180.0, true, true ), BooleanClause.Occur.SHOULD ) .add( NumericRangeQuery.newDoubleRange( longitudeFieldName, -180.0, boundingBox.getUpperRight().getLongitude(), true, true ), BooleanClause.Occur.SHOULD ) .build();
Rectangle boundingBox = Rectangle.fromBoundingCircle( center, radius ); latitudeFieldName, boundingBox.getLowerLeft().getLatitude(), boundingBox.getUpperRight().getLatitude(), true, true ); if ( boundingBox.getLowerLeft().getLongitude() <= boundingBox.getUpperRight().getLongitude() ) { longQuery = NumericRangeQuery.newDoubleRange( longitudeFieldName, boundingBox.getLowerLeft().getLongitude(), boundingBox.getUpperRight().getLongitude(), true, true ); .add( NumericRangeQuery.newDoubleRange( longitudeFieldName, boundingBox.getLowerLeft().getLongitude(), 180.0, true, true ), BooleanClause.Occur.SHOULD ) .add( NumericRangeQuery.newDoubleRange( longitudeFieldName, -180.0, boundingBox.getUpperRight().getLongitude(), true, true ), BooleanClause.Occur.SHOULD ) .build();
@Test public void boundingBoxTest() { Point center = Point.fromDegrees( 45, 4 ); Rectangle rectangle = Rectangle.fromBoundingCircle( center, 50 ); Assert.assertEquals( 44.550339, rectangle.getLowerLeft().getLatitude(), 0.000001d ); Assert.assertEquals( 3.359047, rectangle.getLowerLeft().getLongitude(), 0.000001d ); Assert.assertEquals( 45.449660, rectangle.getUpperRight().getLatitude(), 0.000001d ); Assert.assertEquals( 4.640952, rectangle.getUpperRight().getLongitude(), 0.000001d ); } }
Point center = Point.fromDegrees( random.nextDouble() * 2 + 44 , random.nextDouble() * 2 + 3 ); double radius = 25.0d; Rectangle boundingBox = Rectangle.fromBoundingCircle( center, radius ); queryBuilder.range() .onField( "latitude" ) .from( boundingBox.getLowerLeft().getLatitude() ) .to( boundingBox.getUpperRight().getLatitude() ) .createQuery() queryBuilder.range() .onField( "longitude" ) .from( boundingBox.getLowerLeft().getLongitude() ) .to( boundingBox.getUpperRight().getLongitude() ) .createQuery() queryBuilder.range() .onField( "latitude" ) .from( boundingBox.getLowerLeft().getLatitude() ) .to( boundingBox.getUpperRight().getLatitude() ) .createQuery() queryBuilder.range() .onField( "longitude" ) .from( boundingBox.getLowerLeft().getLongitude() ) .to( boundingBox.getUpperRight().getLongitude() ) .createQuery()