microg/GmsCore · error · IllegalArgumentException

Tilt needs to be between 0 and 90 inclusive

Error message

Tilt needs to be between 0 and 90 inclusive

What it means

The CameraPosition(LatLng, float, float, float) constructor throws IllegalArgumentException when the tilt argument is outside the range 0 to 90 degrees inclusive. Tilt controls the viewing angle from directly overhead (0) to horizontally along the ground (90), and values beyond 90 are not representable by the map renderer. The check runs after the null-target check, so a valid non-null target is required first.

Source

Thrown at play-services-maps/src/main/java/com/google/android/gms/maps/model/CameraPosition.java:89

     * @param zoom    Zoom level at target. See {@link #zoom} for details of restrictions.
     * @param tilt    The camera angle, in degrees, from the nadir (directly down). See
     *                {@link #tilt} for details of restrictions.
     * @param bearing Direction that the camera is pointing in, in degrees clockwise from north.
     *                This value will be normalized to be within 0 degrees inclusive and 360
     *                degrees exclusive.
     * @throws NullPointerException     if {@code target} is {@code null}
     * @throws IllegalArgumentException if {@code tilt} is outside range of {@code 0} to {@code 90}
     *                                  degrees inclusive
     */
    public CameraPosition(LatLng target, float zoom, float tilt, float bearing)
            throws NullPointerException, IllegalArgumentException {
        if (target == null) {
            throw new NullPointerException("null camera target");
        }
        this.target = target;
        this.zoom = zoom;
        if (tilt < 0 || 90 < tilt) {
            throw new IllegalArgumentException("Tilt needs to be between 0 and 90 inclusive");
        }
        this.tilt = tilt;
        if (bearing <= 0) {
            bearing += 360;
        }
        this.bearing = bearing % 360;
    }

    /**
     * Creates a builder for a camera position.
     */
    public static Builder builder() {
        return new Builder();
    }

    /**
     * Creates a builder for a camera position, initialized to a given position.
     */

View on GitHub (pinned to 157c9d86ac)

Solutions

  1. Clamp the tilt value into [0, 90] with Math.max(0f, Math.min(90f, tilt)) before constructing the CameraPosition.
  2. If tilt comes from user input or animation, normalize it at the source (slider bounds, interpolator output).
  3. Check the numeric range before calling the constructor and reject or adjust out-of-range values.

Example fix

// before
float tilt = interpolateTilt(t); // may exceed 90
CameraPosition pos = new CameraPosition(target, 15f, tilt, 0f);

// after
float tilt = Math.max(0f, Math.min(90f, interpolateTilt(t)));
CameraPosition pos = new CameraPosition(target, 15f, tilt, 0f);
Defensive patterns

Strategy: validation

Validate before calling

if (tilt < 0f || tilt > 90f) tilt = Math.max(0f, Math.min(90f, tilt));

Type guard

float clampTilt(float t) { return Math.max(0f, Math.min(90f, t)); }

Try / catch

try {
    CameraPosition pos = new CameraPosition(target, zoom, tilt, bearing);
} catch (IllegalArgumentException e) {
    CameraPosition pos = new CameraPosition(target, zoom, clampTilt(tilt), bearing);
}

Prevention

When it happens

Trigger: Calling new CameraPosition(target, zoom, tilt, bearing) with tilt < 0 or tilt > 90, e.g. computing tilt from a gesture, sensor, or animation interpolation that overshoots the range, or passing a fractional/interpolated value like 90.5 during camera animation.

Common situations: Camera animation code that lerps between two tilts and slightly overshoots the endpoint due to floating-point math; UI sliders without clamping that let users enter values above 90; porting code from other map SDKs that allow steeper angles.

Related errors


AI-assisted analysis of microg/GmsCore@157c9d86ac (2026-09-06). Data as JSON: /api/errors/1eb2be4d5f89606f. Report an issue: GitHub.