[android] LatLngBounds: latNorth should be greater or equal than latSouth

This commit is contained in:
Osana Babayan
2018-02-27 18:27:22 +01:00
committed by GitHub
parent 977e9f118c
commit 43a7db0b0b
2 changed files with 13 additions and 0 deletions

View File

@@ -283,6 +283,8 @@ public class LatLngBounds implements Parcelable {
* This values of latNorth and latSouth should be in the range of [-90, 90],
* see {@link GeometryConstants#MIN_LATITUDE} and {@link GeometryConstants#MAX_LATITUDE},
* otherwise IllegalArgumentException will be thrown.
* latNorth should be greater or equal latSouth, otherwise IllegalArgumentException will be thrown.
*
* <p>
* This method doesn't recalculate most east or most west boundaries.
* Note that lonEast and lonWest will be wrapped to be in the range of [-180, 180],
@@ -312,6 +314,10 @@ public class LatLngBounds implements Parcelable {
throw new IllegalArgumentException("latitude must be between -90 and 90");
}
if (latNorth < latSouth) {
throw new IllegalArgumentException("LatSouth cannot be less than latNorth");
}
lonEast = LatLng.wrap(lonEast, GeometryConstants.MIN_LONGITUDE, GeometryConstants.MAX_LONGITUDE);
lonWest = LatLng.wrap(lonWest, GeometryConstants.MIN_LONGITUDE, GeometryConstants.MAX_LONGITUDE);

View File

@@ -496,4 +496,11 @@ public class LatLngBoundsTest {
exception.expectMessage("longitude must not be infinite");
LatLngBounds.from(20, 20, 0, Double.POSITIVE_INFINITY);
}
@Test
public void testConstructorCheckLatSouthGreaterLatNorth() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("LatSouth cannot be less than latNorth");
LatLngBounds.from(0, 20, 20, 0);
}
}