microg/GmsCore · error · IllegalArgumentException

Geofence region not set.

Error message

Geofence region not set.

What it means

build() checks that a circular region was configured: regionType is -1 until setCircularRegion(latitude, longitude, radius) is called. Without a region there is nothing to monitor, so the builder throws IllegalArgumentException.

Source

Thrown at play-services-location/src/main/java/com/google/android/gms/location/Geofence.java:120

        private String requestId;
        private @TransitionTypes int transitionTypes;

        /**
         * Creates a geofence object.
         *
         * @throws IllegalArgumentException if any parameters are not set or out of range
         */
        public Geofence build() throws IllegalArgumentException {
            if (requestId == null) {
                throw new IllegalArgumentException("Request ID not set.");
            } else if (transitionTypes == 0) {
                throw new IllegalArgumentException("Transition types not set.");
            } else if ((transitionTypes & GEOFENCE_TRANSITION_DWELL) > 0 && loiteringDelay < 0) {
                throw new IllegalArgumentException("Non-negative loitering delay needs to be set when transition types include GEOFENCE_TRANSITION_DWELLING.");
            } else if (expirationTime == Long.MIN_VALUE) {
                throw new IllegalArgumentException("Expiration not set.");
            } else if (regionType == -1) {
                throw new IllegalArgumentException("Geofence region not set.");
            } else if (notificationResponsiveness < 0) {
                throw new IllegalArgumentException("Notification responsiveness should be nonnegative.");
            } else {
                return new ParcelableGeofence(requestId, expirationTime, regionType, latitude, longitude, radius, transitionTypes, notificationResponsiveness, loiteringDelay);
            }
        }

        /**
         * Sets the region of this geofence. The geofence represents a circular area on a flat, horizontal plane.
         *
         * @param latitude  latitude in degrees, between -90 and +90 inclusive
         * @param longitude longitude in degrees, between -180 and +180 inclusive
         * @param radius    radius in meters
         */
        public Builder setCircularRegion(@FloatRange(from = -90.0d, to = 90.0d) double latitude, @FloatRange(from = -180.0d, to = 180.0d) double longitude, @FloatRange(from = 0.0d, fromInclusive = false) float radius) {
            this.regionType = 1;
            this.latitude = latitude;
            this.longitude = longitude;

View on GitHub (pinned to 157c9d86ac)

Solutions

  1. Call setCircularRegion(latitude, longitude, radiusInMeters) before build()
  2. Ensure the radius is a positive finite value and coordinates are valid

Example fix

// before
Geofence fence = new Geofence.Builder()
    .setRequestId("fence1")
    .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER)
    .setExpirationDuration(3600000)
    .build(); // throws
// after
Geofence fence = new Geofence.Builder()
    .setRequestId("fence1")
    .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER)
    .setExpirationDuration(3600000)
    .setCircularRegion(37.4219, -122.0840, 100f)
    .build();
Defensive patterns

Strategy: validation

Validate before calling

if (Double.isNaN(lat) || Double.isNaN(lng) || radius <= 0) {
    throw new IllegalStateException("Valid circular region required before build()");
}

Try / catch

try { return builder.build(); } catch (IllegalArgumentException e) { if (e.getMessage().contains("region")) { throw new IllegalArgumentException("Geofence requires setCircularRegion(lat, lng, radius)", e); } throw e; }

Prevention

When it happens

Trigger: Calling build() without calling setCircularRegion(double, double, float) on the builder.

Common situations: Forgetting the region when assembling a long builder chain; passing NaN/placeholder values elsewhere and skipping the region call; dynamic fence construction where the coordinates branch is skipped.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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