elastic/elasticsearch · error · IllegalArgumentException
invalid latitude
Error message
invalid latitude
What it means
Thrown by GeographyValidator.checkLatitude when a latitude value is NaN or falls outside the inclusive range [-90.0, 90.0]. Geographic coordinates require latitude to stay within the pole-to-pole range; anything else is treated as corrupt input. The bounds are inclusive on both ends.
Source
Thrown at libs/geo/src/main/java/org/elasticsearch/geometry/utils/GeographyValidator.java:71
*/
private static final double MAX_LAT_INCL = 90.0D;
private final boolean ignoreZValue;
protected GeographyValidator(boolean ignoreZValue) {
this.ignoreZValue = ignoreZValue;
}
public static GeometryValidator instance(boolean ignoreZValue) {
return ignoreZValue ? TRUE : FALSE;
}
/**
* validates latitude value is within standard +/-90 coordinate bounds
*/
protected void checkLatitude(double latitude) {
if (Double.isNaN(latitude) || latitude < MIN_LAT_INCL || latitude > MAX_LAT_INCL) {
throw new IllegalArgumentException(
"invalid latitude " + latitude + "; must be between " + MIN_LAT_INCL + " and " + MAX_LAT_INCL
);
}
}
/**
* validates longitude value is within standard +/-180 coordinate bounds
*/
protected void checkLongitude(double longitude) {
if (Double.isNaN(longitude) || longitude < MIN_LON_INCL || longitude > MAX_LON_INCL) {
throw new IllegalArgumentException(
"invalid longitude " + longitude + "; must be between " + MIN_LON_INCL + " and " + MAX_LON_INCL
);
}
}
protected void checkAltitude(double zValue) {
if (ignoreZValue == false && Double.isNaN(zValue) == false) {View on GitHub (pinned to db6a809a66)
Solutions
- Confirm the value is latitude and is in [-90, 90]; clamp or reject out-of-range values upstream.
- Check for swapped lat/lon — if the failing value looks like a longitude (>90), the columns are reversed.
- Filter NaN before validation if missing data should be skipped rather than rejected.
Example fix
// before GeographyValidator.instance(true).validateCoordinate(120.0, 130.0, Double.NaN); // lat=130 invalid // after GeographyValidator.instance(true).validateCoordinate(130.0, 120.0, Double.NaN); // lon=130, lat=120 -> still bad GeographyValidator.instance(true).validateCoordinate(130.0, 45.0, Double.NaN); // correct: lon=130, lat=45
Defensive patterns
Strategy: validation
Validate before calling
if (Double.isNaN(lat) || lat < -90.0 || lat > 90.0) {
throw new IllegalArgumentException("latitude out of range: " + lat);
}
GeographyValidator.instance(ignoreZ).validateCoordinate(lon, lat, z); Type guard
static boolean isValidLatitude(double lat) {
return !Double.isNaN(lat) && lat >= -90.0 && lat <= 90.0;
} Prevention
- Check for swapped lat/lon — a value > 90 in the latitude slot usually means columns are reversed.
- Clamp or reject out-of-range latitudes at ingestion.
- Filter NaN latitudes if missing data should be skipped.
When it happens
Trigger: Any path that calls checkLatitude directly or indirectly (validateCoordinate, validate(Geometry) on a geometry containing points, etc.) with a y-value that is NaN, less than -90.0, or greater than 90.0.
Common situations: Swapped lat/lon columns in source data (longitude 120 sent as latitude); unbounded numeric inputs not clamped before validation; null/missing values converted to NaN; projections or computations that overflow the valid range.
Related errors
- invalid longitude
- found Z value [
- max y cannot be less than min y
- max y cannot be less than min y
- only one z value is specified
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/676c6620e24a2926.
Report an issue: GitHub.