@@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.geometry;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.FloatRange;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
@@ -223,11 +224,42 @@ public class LatLngBounds implements Parcelable {
|
||||
|
||||
/**
|
||||
* Constructs a LatLngBounds from doubles representing a LatLng pair.
|
||||
*
|
||||
* 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.
|
||||
* <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],
|
||||
* see {@link GeometryConstants#MIN_LONGITUDE} and {@link GeometryConstants#MAX_LONGITUDE}
|
||||
* </p>
|
||||
*/
|
||||
public static LatLngBounds from(double latNorth, double lonEast, double latSouth, double lonWest) {
|
||||
public static LatLngBounds from(
|
||||
@FloatRange(from = GeometryConstants.MIN_LATITUDE, to = GeometryConstants.MAX_LATITUDE) double latNorth,
|
||||
double lonEast,
|
||||
@FloatRange(from = GeometryConstants.MIN_LATITUDE, to = GeometryConstants.MAX_LATITUDE) double latSouth,
|
||||
double lonWest) {
|
||||
|
||||
if (Double.isNaN(latNorth) || Double.isNaN(latSouth)) {
|
||||
throw new IllegalArgumentException("latitude must not be NaN");
|
||||
}
|
||||
|
||||
if (Double.isNaN(lonEast) || Double.isNaN(lonWest)) {
|
||||
throw new IllegalArgumentException("longitude must not be NaN");
|
||||
}
|
||||
|
||||
if (Double.isInfinite(lonEast) || Double.isInfinite(lonWest)) {
|
||||
throw new IllegalArgumentException("longitude must not be infinite");
|
||||
}
|
||||
|
||||
if (latNorth > GeometryConstants.MAX_LATITUDE || latNorth < GeometryConstants.MIN_LATITUDE
|
||||
|| latSouth > GeometryConstants.MAX_LATITUDE || latSouth < GeometryConstants.MIN_LATITUDE) {
|
||||
throw new IllegalArgumentException("latitude must be between -90 and 90");
|
||||
}
|
||||
|
||||
lonEast = LatLng.wrap(lonEast, GeometryConstants.MIN_LONGITUDE, GeometryConstants.MAX_LONGITUDE);
|
||||
lonWest = LatLng.wrap(lonWest, GeometryConstants.MIN_LONGITUDE, GeometryConstants.MAX_LONGITUDE);
|
||||
|
||||
return new LatLngBounds(latNorth, lonEast, latSouth, lonWest);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user