{"record":{"id":"55a80d254a5636e4","repo":"microg/GmsCore","slug":"invalid-latitude","errorCode":null,"errorMessage":"invalid latitude: ","messagePattern":"invalid latitude: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"play-services-location/core/system-api/src/main/java/android/location/Geofence.java","lineNumber":78,"sourceCode":"    /** @hide */\n    public double getLongitude() {\n        return mLongitude;\n    }\n\n    /** @hide */\n    public float getRadius() {\n        return mRadius;\n    }\n\n    private static void checkRadius(float radius) {\n        if (radius <= 0) {\n            throw new IllegalArgumentException(\"invalid radius: \" + radius);\n        }\n    }\n\n    private static void checkLatLong(double latitude, double longitude) {\n        if (latitude > 90.0 || latitude < -90.0) {\n            throw new IllegalArgumentException(\"invalid latitude: \" + latitude);\n        }\n        if (longitude > 180.0 || longitude < -180.0) {\n            throw new IllegalArgumentException(\"invalid longitude: \" + longitude);\n        }\n    }\n\n    private static void checkType(int type) {\n        if (type != TYPE_HORIZONTAL_CIRCLE) {\n            throw new IllegalArgumentException(\"invalid type: \" + type);\n        }\n    }\n\n    public static final Parcelable.Creator<Geofence> CREATOR = new Parcelable.Creator<Geofence>() {\n        @Override\n        public Geofence createFromParcel(Parcel in) {\n            int type = in.readInt();\n            double latitude = in.readDouble();\n            double longitude = in.readDouble();","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-location/core/system-api/src/main/java/android/location/Geofence.java#L60-L96","documentation":"Geofence.Builder throws IllegalArgumentException(\"invalid latitude: \" + latitude) when checkLatLong receives a latitude outside the valid WGS-84 range [-90.0, 90.0]. The library validates coordinates at build time before any geofence can be registered.","triggerScenarios":"Calling setCircularRegion with latitude > 90, < -90, NaN, or Infinity while building the Geofence via Geofence.Builder.create().","commonSituations":"Swapped lat/long values (common when copying from (lng, lat) ordered sources like GeoJSON); uninitialized doubles; parsing coordinates from user input or APIs without bounds checks; unit/degrees-vs-radians mistakes.","solutions":["Swap lat/long if values were passed in the wrong order — |value| > 90 usually means a longitude was given as latitude","Validate the coordinate is in [-90, 90] and finite before calling setCircularRegion","Check the upstream data format: GeoJSON uses (lon, lat) ordering, most map SDKs use (lat, lng)"],"exampleFix":"// before\nbuilder.setCircularRegion(lon, lat, radius); // swapped\n// after\nif (lat < -90 || lat > 90 || Double.isNaN(lat))\n    throw new IllegalArgumentException(\"latitude out of range: \" + lat);\nbuilder.setCircularRegion(lat, lon, radius);","handlingStrategy":"validation","validationCode":"public static boolean isValidLatitude(double lat) {\n    return Double.isFinite(lat) && lat >= -90.0 && lat <= 90.0;\n}","typeGuard":null,"tryCatchPattern":"try {\n    Geofence g = new Geofence.Builder()\n        .setRequestId(id).setCircularRegion(lat, lon, radius).build();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"invalid latitude\")) {\n        // likely swapped lat/long — check caller argument order\n    }\n}","preventionTips":["Remember |lat| > 90 usually means a longitude was passed as latitude","GeoJSON is (lon, lat); map SDKs are (lat, lon) — normalize your data pipeline","Validate all coordinates on ingest, not at geofence build time"],"tags":["android","geofencing","validation","location"],"backgroundTag":"value-out-of-range","analyzedSha":"157c9d86ac46c195a86c2f15ab55c84036223f95","analyzedAt":"2026-09-06T17:27:33.892Z","contentChangedAt":"2026-09-06T17:27:33.892Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}