AI-generated Key Takeaways
-
Geofence.Builderis used to construct aGeofenceobject. -
Key methods allow setting the circular region, expiration duration, loitering delay, notification responsiveness, request ID, and transition types of the geofence.
-
The
build()method creates the geofence object and throws anIllegalArgumentExceptionif parameters are not set or are out of range.
A builder that builds Geofence.
Public Constructor Summary
|
Builder()
|
Public Method Summary
| Geofence |
build()
Creates a geofence object.
|
| Geofence.Builder |
setCircularRegion(double latitude, double longitude, float radius)
Sets the region of this geofence.
|
| Geofence.Builder |
setExpirationDuration(long durationMillis)
Sets the expiration duration of geofence.
|
| Geofence.Builder |
setLoiteringDelay(int loiteringDelayMs)
Sets the delay between
Geofence.GEOFENCE_TRANSITION_ENTER and
Geofence.GEOFENCE_TRANSITION_DWELL in milliseconds.
|
| Geofence.Builder |
setNotificationResponsiveness(int notificationResponsivenessMs)
Sets the best-effort notification responsiveness of the geofence.
|
| Geofence.Builder | |
| Geofence.Builder |
setTransitionTypes(int transitionTypes)
Sets the transition types of interest.
|
Inherited Method Summary
Public Constructors
public Builder ()
Public Methods
public Geofence build ()
Creates a geofence object.
Throws
| IllegalArgumentException | if any parameters are not set or out of range |
|---|
public Geofence.Builder setCircularRegion (double latitude, double longitude, float radius)
Sets the region of this geofence. The geofence represents a circular area on a flat, horizontal plane.
Parameters
| latitude | latitude in degrees, between -90 and +90 inclusive |
|---|---|
| longitude | longitude in degrees, between -180 and +180 inclusive |
| radius | radius in meters |
public Geofence.Builder setExpirationDuration (long durationMillis)
Sets the expiration duration of geofence. The geofence will be removed automatically after this period of time. By default the geofence will never expire.
public Geofence.Builder setLoiteringDelay (int loiteringDelayMs)
Sets the delay between
Geofence.GEOFENCE_TRANSITION_ENTER and
Geofence.GEOFENCE_TRANSITION_DWELL in milliseconds. For example, if
loitering delay is set to 300000 ms (i.e. 5 minutes) the geofence service will send a
Geofence.GEOFENCE_TRANSITION_DWELL alert roughly 5 minutes after user enters
a geofence if the user stays inside the geofence during this period of time. If the
user exits from the geofence in this amount of time,
Geofence.GEOFENCE_TRANSITION_DWELL alert won't be sent.
This value is ignored if the transition types don't include a
Geofence.GEOFENCE_TRANSITION_DWELL filter.
Parameters
| loiteringDelayMs | the delay for confirming dwelling, in milliseconds |
|---|
public Geofence.Builder setNotificationResponsiveness (int notificationResponsivenessMs)
Sets the best-effort notification responsiveness of the geofence. Defaults to 0. Setting a big responsiveness value, for example 5 minutes, can save power significantly. However, setting a very small responsiveness value, for example 5 seconds, doesn't necessarily mean you will get notified right after the user enters or exits a geofence: internally, the geofence might adjust the responsiveness value to save power when needed.
Parameters
| notificationResponsivenessMs | (milliseconds) defines the best-effort description of how soon should the callback be called when the transition associated with the geofence is triggered. For instance, if set to 300000 milliseconds the callback will be called 5 minutes within entering or exiting the geofence. |
|---|
public Geofence.Builder setRequestId (String requestId)
Sets the request ID of the geofence. Request ID is a string to identify this geofence inside your application. When two geofences with the same requestId are monitored, the new one will replace the old one regardless the geographical region these two geofences represent.
Parameters
| requestId | the request ID. The length of the string can be up to 100 characters. |
|---|
public Geofence.Builder setTransitionTypes (int transitionTypes)
Sets the transition types of interest. Alerts are only generated for the given transition types. By default the geofence will alert for enter and exit transitions.
Parameters
| transitionTypes | geofence transition types of interest, as a bitwise-OR of
GEOFENCE_TRANSITION_ flags. |
|---|