Geofence
Stay organized with collections
Save and categorize content based on your preferences.
Represents a geographical region, also known as a geofence. Geofences can be monitored by
geofencer service. And when the user crosses the boundary of a geofence, an alert will be
generated.
Nested Class Summary
@interface
Geofence transition event.
@interface
Geofence transition types of interest, as either
0 or a bitwise-OR of GEOFENCE_TRANSITION_
flags.
Public Method Summary
abstract long |
|
abstract double |
getLatitude
() Returns latitude in degrees, between -90 and +90 inclusive.
|
abstract int |
|
abstract double |
getLongitude
() Returns longitude in degrees, between -180 and +180 inclusive.
|
abstract int |
getNotificationResponsiveness
() Returns the best-effort description of how soon should the callback be called
when the transition associated with the geofence is triggered, in milliseconds.
|
abstract float |
|
abstract String
|
|
abstract int |
getTransitionTypes
() Returns the transition types of interest as a bitwise-OR of GEOFENCE_TRANSITION_
flags.
|
Constants
public static final int
GEOFENCE_TRANSITION_DWELL
public static final int
GEOFENCE_TRANSITION_ENTER
The transition type indicating that the user enters the geofence(s).
Constant Value:
1
public static final int
GEOFENCE_TRANSITION_EXIT
The transition type indicating that the user exits the geofence(s).
Constant Value:
2
public static final long
NEVER_EXPIRE
Expiration value that indicates the geofence should never expire.
Constant Value:
-1
Public Methods
public abstract long
getExpirationTime
()
Returns the expiration elapsed realtime of geofence in milliseconds, or NEVER_EXPIRE
if there's no expiration. When positive, this geofence will be removed automatically
after that time.
public abstract double
getLatitude
()
Returns latitude in degrees, between -90 and +90 inclusive.
public abstract int
getLoiteringDelay
()
public abstract double
getLongitude
()
Returns longitude in degrees, between -180 and +180 inclusive.
public abstract int
getNotificationResponsiveness
()
Returns the best-effort description of how soon should the callback be called when
the transition associated with the geofence is triggered, in milliseconds.
public abstract float
getRadius
()
Returns radius in meters.
public abstract String
getRequestId
()
Returns the request ID of this geofence. The 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.
public abstract int
getTransitionTypes
()
Returns the transition types of interest as a bitwise-OR of GEOFENCE_TRANSITION_
flags.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License
, and code samples are licensed under the Apache 2.0 License
. For details, see the Google Developers Site Policies
. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-10-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-10-31 UTC."],[[["\u003cp\u003e\u003ccode\u003eGeofence\u003c/code\u003e represents a geographical region that can be monitored for user entry, exit, and dwelling.\u003c/p\u003e\n"],["\u003cp\u003eWhen a user crosses a geofence boundary, an alert is generated by the geofencer service.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can define the geofence's latitude, longitude, radius, and transition types using the \u003ccode\u003eGeofence.Builder\u003c/code\u003e class.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eGeofence\u003c/code\u003e provides methods to retrieve information about the geofence, such as expiration time, transition types, and request ID.\u003c/p\u003e\n"],["\u003cp\u003eConstants like \u003ccode\u003eGEOFENCE_TRANSITION_ENTER\u003c/code\u003e, \u003ccode\u003eGEOFENCE_TRANSITION_EXIT\u003c/code\u003e, and \u003ccode\u003eGEOFENCE_TRANSITION_DWELL\u003c/code\u003e define the types of geofence transitions.\u003c/p\u003e\n"]]],[],null,["# Geofence\n\npublic interface **Geofence** \nRepresents a geographical region, also known as a geofence. Geofences can be monitored by\ngeofencer service. And when the user crosses the boundary of a geofence, an alert will be\ngenerated. \n\n### Nested Class Summary\n\n|------------|---|---|-----------------------------------------------------------------------------------------------------|\n| class | [Geofence.Builder](/android/reference/com/google/android/gms/location/Geofence.Builder) || A builder that builds [Geofence](/android/reference/com/google/android/gms/location/Geofence). |\n| @interface | [Geofence.GeofenceTransition](/android/reference/com/google/android/gms/location/Geofence.GeofenceTransition) || Geofence transition event. |\n| @interface | [Geofence.TransitionTypes](/android/reference/com/google/android/gms/location/Geofence.TransitionTypes) || Geofence transition types of interest, as either 0 or a bitwise-OR of `GEOFENCE_TRANSITION_` flags. |\n\n### Constant Summary\n\n|------|--------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|\n| int | [GEOFENCE_TRANSITION_DWELL](/android/reference/com/google/android/gms/location/Geofence#GEOFENCE_TRANSITION_DWELL) | The transition type indicating that the user enters and dwells in geofences for a given period of time. |\n| int | [GEOFENCE_TRANSITION_ENTER](/android/reference/com/google/android/gms/location/Geofence#GEOFENCE_TRANSITION_ENTER) | The transition type indicating that the user enters the geofence(s). |\n| int | [GEOFENCE_TRANSITION_EXIT](/android/reference/com/google/android/gms/location/Geofence#GEOFENCE_TRANSITION_EXIT) | The transition type indicating that the user exits the geofence(s). |\n| long | [NEVER_EXPIRE](/android/reference/com/google/android/gms/location/Geofence#NEVER_EXPIRE) | Expiration value that indicates the geofence should never expire. |\n\n### Public Method Summary\n\n|----------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract long | [getExpirationTime](/android/reference/com/google/android/gms/location/Geofence#getExpirationTime())() Returns the expiration elapsed realtime of geofence in milliseconds, or [NEVER_EXPIRE](/android/reference/com/google/android/gms/location/Geofence#NEVER_EXPIRE) if there's no expiration. |\n| abstract double | [getLatitude](/android/reference/com/google/android/gms/location/Geofence#getLatitude())() Returns latitude in degrees, between -90 and +90 inclusive. |\n| abstract int | [getLoiteringDelay](/android/reference/com/google/android/gms/location/Geofence#getLoiteringDelay())() Returns the delay between [GEOFENCE_TRANSITION_ENTER](/android/reference/com/google/android/gms/location/Geofence#GEOFENCE_TRANSITION_ENTER) and [GEOFENCE_TRANSITION_DWELL](/android/reference/com/google/android/gms/location/Geofence#GEOFENCE_TRANSITION_DWELL) in milliseconds. |\n| abstract double | [getLongitude](/android/reference/com/google/android/gms/location/Geofence#getLongitude())() Returns longitude in degrees, between -180 and +180 inclusive. |\n| abstract int | [getNotificationResponsiveness](/android/reference/com/google/android/gms/location/Geofence#getNotificationResponsiveness())() Returns the best-effort description of how soon should the callback be called when the transition associated with the geofence is triggered, in milliseconds. |\n| abstract float | [getRadius](/android/reference/com/google/android/gms/location/Geofence#getRadius())() Returns radius in meters. |\n| abstract [String](//developer.android.com/reference/java/lang/String.html) | [getRequestId](/android/reference/com/google/android/gms/location/Geofence#getRequestId())() Returns the request ID of this geofence. |\n| abstract int | [getTransitionTypes](/android/reference/com/google/android/gms/location/Geofence#getTransitionTypes())() Returns the transition types of interest as a bitwise-OR of `GEOFENCE_TRANSITION_` flags. |\n\nConstants\n---------\n\n#### public static final int\n**GEOFENCE_TRANSITION_DWELL**\n\nThe transition type indicating that the user enters and dwells in geofences for a\ngiven period of time. If [GEOFENCE_TRANSITION_ENTER](/android/reference/com/google/android/gms/location/Geofence#GEOFENCE_TRANSITION_ENTER) is also specified, this alert will always be sent\nafter the [GEOFENCE_TRANSITION_ENTER](/android/reference/com/google/android/gms/location/Geofence#GEOFENCE_TRANSITION_ENTER) alert.\n\nYou must set the duration of loitering before this alert is sent using\n[Geofence.Builder.setLoiteringDelay(int)](/android/reference/com/google/android/gms/location/Geofence.Builder#setLoiteringDelay(int)). \nConstant Value: 4 \n\n#### public static final int\n**GEOFENCE_TRANSITION_ENTER**\n\nThe transition type indicating that the user enters the geofence(s). \nConstant Value: 1 \n\n#### public static final int\n**GEOFENCE_TRANSITION_EXIT**\n\nThe transition type indicating that the user exits the geofence(s). \nConstant Value: 2 \n\n#### public static final long\n**NEVER_EXPIRE**\n\nExpiration value that indicates the geofence should never expire. \nConstant Value: -1\n\nPublic Methods\n--------------\n\n#### public abstract long **getExpirationTime** ()\n\nReturns the expiration elapsed realtime of geofence in milliseconds, or\n[NEVER_EXPIRE](/android/reference/com/google/android/gms/location/Geofence#NEVER_EXPIRE)\nif there's no expiration. When positive, this geofence will be removed automatically\nafter that time. \n\n#### public abstract double\n**getLatitude** ()\n\nReturns latitude in degrees, between -90 and +90 inclusive. \n\n#### public abstract int **getLoiteringDelay** ()\n\nReturns the delay between [GEOFENCE_TRANSITION_ENTER](/android/reference/com/google/android/gms/location/Geofence#GEOFENCE_TRANSITION_ENTER) and [GEOFENCE_TRANSITION_DWELL](/android/reference/com/google/android/gms/location/Geofence#GEOFENCE_TRANSITION_DWELL) in milliseconds. \n\n#### public abstract double\n**getLongitude** ()\n\nReturns longitude in degrees, between -180 and +180 inclusive. \n\n#### public abstract int **getNotificationResponsiveness** ()\n\nReturns the best-effort description of how soon should the callback be called when\nthe transition associated with the geofence is triggered, in milliseconds. \n\n#### public abstract float **getRadius** ()\n\nReturns radius in meters. \n\n#### public abstract [String](//developer.android.com/reference/java/lang/String.html) **getRequestId** ()\n\nReturns the request ID of this geofence. The request ID is a string to identify this\ngeofence inside your application. When two geofences with the same requestId are\nmonitored, the new one will replace the old one regardless the geographical region\nthese two geofences represent. \n\n#### public abstract int **getTransitionTypes** ()\n\nReturns the transition types of interest as a bitwise-OR of\n`GEOFENCE_TRANSITION_` flags."]]