{"record":{"id":"996160b56fcb9645","repo":"microg/GmsCore","slug":"invalid-longitude","errorCode":null,"errorMessage":"invalid longitude: ","messagePattern":"invalid longitude: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"play-services-location/core/system-api/src/main/java/android/location/Geofence.java","lineNumber":81,"sourceCode":"    }\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();\n            float radius = in.readFloat();\n            checkType(type);\n            return Geofence.createCircle(latitude, longitude, radius);","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-location/core/system-api/src/main/java/android/location/Geofence.java#L63-L99","documentation":"Range validation in Geofence.checkLatLong: the longitude is outside [-180.0, 180.0], so the geofence center is invalid. The offending value is appended; applied when constructing a Geofence from builder input or parcel data.","triggerScenarios":"Calling setCircularRegion with longitude > 180, < -180, NaN, or Infinity (e.g. values in radians, or cumulative heading values exceeding a full circle) before create().","commonSituations":"Passing radians instead of degrees; not normalizing longitudes that wrap around the antimeridian (e.g. 190 instead of -170); uninitialized or misparsed coordinate fields; swapped/offset column parsing.","solutions":["Normalize the longitude into [-180, 180] (e.g. ((lon + 540) % 360) - 180) before building the geofence","Convert radians to degrees if the source uses radians (Math.toDegrees)","Validate the value is finite and within range before calling setCircularRegion"],"exampleFix":"// before\nbuilder.setCircularRegion(lat, lonRadians, radius);\n// after\ndouble lonDeg = Math.toDegrees(lonRadians);\nlonDeg = ((lonDeg + 540.0) % 360.0) - 180.0; // normalize to [-180,180]\nbuilder.setCircularRegion(lat, lonDeg, radius);","handlingStrategy":"validation","validationCode":"public static double normalizeLongitude(double lon) {\n    return ((lon + 540.0) % 360.0 + 360.0) % 360.0 - 180.0;\n}\n// call normalizeLongitude before setCircularRegion","typeGuard":"public static boolean isValidLongitude(double lon) {\n    return Double.isFinite(lon) && lon >= -180.0 && lon <= 180.0;\n}","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 longitude\")) {\n        // normalize or convert radians before retrying\n    }\n}","preventionTips":["Normalize wrapping longitudes (antimeridian) into [-180, 180]","Convert radians to degrees with Math.toDegrees when sources are radian-based","Validate coordinates are finite and in range before building geofences"],"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-14T00:17:10.932Z"}