LocationFence
Stay organized with collections
Save and categorize content based on your preferences.
Use this class to create location-based fences.
Note: Values that indicate a changing state are momentarily TRUE
for about 5 seconds, then automatically revert to FALSE
.
Public Method Summary
static AwarenessFence
|
entering
(double latitude, double longitude, double radius) This fence is momentarily (about 5 seconds) in the TRUE
state when the user enters the specified circle.
|
static AwarenessFence
|
exiting
(double latitude, double longitude, double radius) This fence is momentarily (about 5 seconds) in the TRUE
state when the user exits the specified circle.
|
static AwarenessFence
|
in
(double latitude, double longitude, double radius, long
dwellTimeMillis) This fence is in the TRUE
state when the user's location is within the specified circle,
and the user has been in the circle for at least the dwellTimeMillis
that was specified.
|
Inherited Method Summary
From class java.lang.Object
Public Methods
public static AwarenessFence
entering
(double
latitude, double longitude, double radius)
This fence is momentarily (about 5 seconds) in the TRUE
state when the user enters the specified circle.
To use this method, your app must declare the android.permission.ACCESS_FINE_LOCATION
permission in AndroidManifest.xml,
and the user must provide consent at runtime.
Parameters
public static AwarenessFence
exiting
(double latitude,
double longitude, double radius)
This fence is momentarily (about 5 seconds) in the TRUE
state when the user exits the specified circle.
Your app must declare the android.permission.ACCESS_FINE_LOCATION
permission in your AndroidManifest and be granted this permission to use this API.
Parameters
public static AwarenessFence
in
(double latitude,
double longitude, double radius, long dwellTimeMillis)
This fence is in the TRUE
state when the user's location is within the specified circle, and the user has been in
the circle for at least the dwellTimeMillis
that was specified.
To use this method, your app must declare the android.permission.ACCESS_FINE_LOCATION
permission in AndroidManifest.xml,
and the user must provide consent at runtime.
Parameters
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\u003eThe \u003ccode\u003eLocationFence\u003c/code\u003e class is used to create location-based fences, triggering actions when a user enters, exits, or dwells within a defined circular area.\u003c/p\u003e\n"],["\u003cp\u003eFences for entering and exiting a location are momentarily true for about 5 seconds, requiring immediate action based on the trigger.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ein\u003c/code\u003e fence allows you to specify a dwell time, ensuring the user remains within the location for a minimum duration before triggering.\u003c/p\u003e\n"],["\u003cp\u003eUsing \u003ccode\u003eLocationFence\u003c/code\u003e requires the \u003ccode\u003eandroid.permission.ACCESS_FINE_LOCATION\u003c/code\u003e permission and user consent.\u003c/p\u003e\n"]]],[],null,["# LocationFence\n\npublic final class **LocationFence** extends [Object](//developer.android.com/reference/java/lang/Object.html) \nUse this class to create location-based fences.\n\nNote: Values that indicate a changing state are momentarily [TRUE](/android/reference/com/google/android/gms/awareness/fence/FenceState#TRUE)\nfor about 5 seconds, then automatically revert to [FALSE](/android/reference/com/google/android/gms/awareness/fence/FenceState#FALSE). \n\n### Public Method Summary\n\n|---------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| static [AwarenessFence](/android/reference/com/google/android/gms/awareness/fence/AwarenessFence) | [entering](/android/reference/com/google/android/gms/awareness/fence/LocationFence#entering(double, double, double))(double latitude, double longitude, double radius) This fence is momentarily (about 5 seconds) in the [TRUE](/android/reference/com/google/android/gms/awareness/fence/FenceState#TRUE) state when the user enters the specified circle. |\n| static [AwarenessFence](/android/reference/com/google/android/gms/awareness/fence/AwarenessFence) | [exiting](/android/reference/com/google/android/gms/awareness/fence/LocationFence#exiting(double, double, double))(double latitude, double longitude, double radius) This fence is momentarily (about 5 seconds) in the [TRUE](/android/reference/com/google/android/gms/awareness/fence/FenceState#TRUE) state when the user exits the specified circle. |\n| static [AwarenessFence](/android/reference/com/google/android/gms/awareness/fence/AwarenessFence) | [in](/android/reference/com/google/android/gms/awareness/fence/LocationFence#in(double, double, double, long))(double latitude, double longitude, double radius, long dwellTimeMillis) This fence is in the [TRUE](/android/reference/com/google/android/gms/awareness/fence/FenceState#TRUE) state when the user's location is within the specified circle, and the user has been in the circle for at least the `dwellTimeMillis` that was specified. |\n\n### Inherited Method Summary\n\nFrom class java.lang.Object \n\n|----------------------------------------------------------------------------|--------------------------------------------------------------------------------|\n| [Object](//developer.android.com/reference/java/lang/Object.html) | clone() |\n| boolean | equals([Object](//developer.android.com/reference/java/lang/Object.html) arg0) |\n| void | finalize() |\n| final [Class](//developer.android.com/reference/java/lang/Class.html)\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| [String](//developer.android.com/reference/java/lang/String.html) | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nPublic Methods\n--------------\n\n#### public static [AwarenessFence](/android/reference/com/google/android/gms/awareness/fence/AwarenessFence)\n**entering** (double latitude, double longitude, double radius)\n\nThis fence is momentarily (about 5 seconds) in the [TRUE](/android/reference/com/google/android/gms/awareness/fence/FenceState#TRUE)\nstate when the user enters the specified circle.\n\nTo use this method, your app must declare the\n`android.permission.ACCESS_FINE_LOCATION` permission in AndroidManifest.xml,\nand the user must provide consent at runtime. \n\n##### Parameters\n\n| latitude | Center latitude of the circle in degrees, between -90 and +90 inclusive. |\n| longitude | Center longitude of the circle in degrees, between -180 and +180 inclusive. |\n| radius | Radius defining the circular region, in meters. |\n|-----------|-----------------------------------------------------------------------------|\n\n##### Returns\n\n- the [AwarenessFence](/android/reference/com/google/android/gms/awareness/fence/AwarenessFence) object representing this fence. \n\n#### public static [AwarenessFence](/android/reference/com/google/android/gms/awareness/fence/AwarenessFence)\n**exiting** (double latitude, double longitude, double radius)\n\nThis fence is momentarily (about 5 seconds) in the [TRUE](/android/reference/com/google/android/gms/awareness/fence/FenceState#TRUE)\nstate when the user exits the specified circle.\n\nYour app must declare the `android.permission.ACCESS_FINE_LOCATION`\npermission in your AndroidManifest and be granted this permission to use this API. \n\n##### Parameters\n\n| latitude | center latitude of the circle in degrees, between -90 and +90 inclusive |\n| longitude | center longitude of the circle in degrees, between -180 and +180 inclusive |\n| radius | radius in meters defining the circular region. |\n|-----------|----------------------------------------------------------------------------|\n\n##### Returns\n\n- the [AwarenessFence](/android/reference/com/google/android/gms/awareness/fence/AwarenessFence) object representing this fence. \n\n#### public static [AwarenessFence](/android/reference/com/google/android/gms/awareness/fence/AwarenessFence)\n**in** (double latitude, double longitude, double radius, long dwellTimeMillis)\n\nThis fence is in the [TRUE](/android/reference/com/google/android/gms/awareness/fence/FenceState#TRUE)\nstate when the user's location is within the specified circle, and the user has been in\nthe circle for at least the `dwellTimeMillis` that was specified.\n\nTo use this method, your app must declare the\n`android.permission.ACCESS_FINE_LOCATION` permission in AndroidManifest.xml,\nand the user must provide consent at runtime. \n\n##### Parameters\n\n| latitude | Center latitude of the circle in degrees, between -90 and +90 inclusive. |\n| longitude | Center longitude of the circle in degrees, between -180 and +180 inclusive. |\n| radius | Radius defining the circular region, in meters. |\n| dwellTimeMillis | Minimum dwelling time inside a location before the fence is in the [TRUE](/android/reference/com/google/android/gms/awareness/fence/FenceState#TRUE) state. Must be a value greater than or equal to 0L. |\n|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n\n##### Returns\n\n- the [AwarenessFence](/android/reference/com/google/android/gms/awareness/fence/AwarenessFence) object representing this fence."]]