Lines Matching full:geofence
12 <li><a href="#RequestGeofences">Request Geofence Monitoring</a></li>
13 <li><a href="#HandleGeofenceTransitions">Handle Geofence Transitions</a></li>
14 <li><a href="#StopGeofenceMonitoring">Stop Geofence Monitoring</a></li>
37 location, you add a radius. The latitude, longitude, and radius define a geofence.
42 allows it to detect when the user enters or exits a geofence. For each geofence, you can ask
44 duration of a geofence by specifying an expiration duration in milliseconds. After the geofence
50 <h2 id="RequestGeofences">Request Geofence Monitoring</h2>
52 The first step in requesting geofence monitoring is to request the necessary permission.
167 Log.d("Geofence Detection",
191 "Geofence Detection");
204 store geofence data in a local database or download it from the network, you need to send
205 a geofence to Location Services as an instance of
206 <code><a href="{@docRoot}reference/com/google/android/gms/location/Geofence.html">Geofence</a></code>,
208 <code><a href="{@docRoot}reference/com/google/android/gms/location/Geofence.Builder.html">Geofence.Builder</a></code>.
210 <code><a href="{@docRoot}reference/com/google/android/gms/location/Geofence.html">Geofence</a></code>
216 Define a circular area for the geofence. Use the latitude and longitude to mark a location
218 location before the geofence is detected. The larger the radius, the more likely the
219 user will trigger a geofence transition alert by approaching the geofence. For example,
225 How long the geofence should remain active. Once the expiration time is reached, Location
226 Services deletes the geofence. Most of the time, you should specify an expiration time, but
231 Location Services can detect when the user steps within the radius of the geofence ("entry")
232 and when the user steps outside the radius of the geofence ("exit"), or both.
234 <dt>Geofence ID</dt>
236 A string that is stored with the geofence. You should make this unique, so that you can
237 use it to remove a geofence from Location Services tracking.
240 <h3>Define geofence storage</h3>
242 A geofencing app needs to read and write geofence data to persistent storage. You shouldn't use
243 <code><a href="{@docRoot}reference/com/google/android/gms/location/Geofence.html">Geofence</a></code>
248 As an example of storing geofence data, the following snippet defines two classes that use
252 <code><a href="{@docRoot}reference/com/google/android/gms/location/Geofence.html">Geofence</a></code>
261 * A single Geofence object, defined by its center and radius.
273 * @param geofenceId The Geofence's request ID
274 * @param latitude Latitude of the Geofence's center.
275 * @param longitude Longitude of the Geofence's center.
276 * @param radius Radius of the geofence circle.
277 * @param expiration Geofence expiration duration
278 * @param transition Type of Geofence transition.
315 * Creates a Location Services Geofence object from a
318 * @return A Geofence object
320 public Geofence toGeofence() {
321 // Build a new Geofence object
322 return new Geofence.Builder()
333 * Storage for geofence values, implemented in SharedPreferences.
338 "com.example.android.geofence.KEY_LATITUDE";
340 "com.example.android.geofence.KEY_LONGITUDE";
342 "com.example.android.geofence.KEY_RADIUS";
344 "com.example.android.geofence.KEY_EXPIRATION_DURATION";
346 "com.example.android.geofence.KEY_TRANSITION_TYPE";
347 // The prefix for flattened geofence keys
349 "com.example.android.geofence.KEY";
351 * Invalid values, used to test geofence storage when
370 * Returns a stored geofence by its id, or returns {@code null}
373 * @param id The ID of a stored geofence
374 * @return A geofence defined by its center and radius. See
378 * Get the latitude for the geofence identified by id, or
385 * Get the longitude for the geofence identified by id, or
392 * Get the radius for the geofence identified by id, or
399 * Get the expiration duration for the geofence identified
406 * Get the transition type for the geofence identified by
421 // Return a true Geofence object
431 * Save a geofence.
432 * @param geofence The SimpleGeofence containing the
435 public void setGeofence(String id, SimpleGeofence geofence) {
442 // Write the Geofence values to SharedPreferences
445 (float) geofence.getLatitude());
448 (float) geofence.getLongitude());
451 geofence.getRadius());
454 geofence.getExpirationDuration());
457 geofence.getTransitionType());
463 * Remove a flattened geofence object from storage by
476 * Given a Geofence object's ID and the name of a field
480 * @param id The ID of a Geofence object
492 <h3>Create Geofence objects</h3>
495 gets geofence data from the UI, stores it in {@code SimpleGeofence} objects, stores these
497 <code><a href="{@docRoot}reference/com/google/android/gms/location/Geofence.html">Geofence</a></code>
504 * Use to set an expiration time for a geofence. After this amount
505 * of time Location Services will stop tracking the geofence.
516 * Handles to UI views containing geofence data
518 // Handle to geofence 1 latitude in the UI
520 // Handle to geofence 1 longitude in the UI
522 // Handle to geofence 1 radius in the UI
524 // Handle to geofence 2 latitude in the UI
526 // Handle to geofence 2 longitude in the UI
528 // Handle to geofence 2 radius in the UI
531 * Internal geofence objects for geofence 1 and 2
536 // Internal List of Geofence objects
537 List<Geofence> mGeofenceList;
545 // Instantiate a new geofence storage area
549 mCurrentGeofences = new ArrayList<Geofence>();
553 * Get the geofence parameters for each geofence from the UI
568 // This geofence records only entry transitions
569 Geofence.GEOFENCE_TRANSITION_ENTER);
579 // This geofence records both entry and exit transitions
580 Geofence.GEOFENCE_TRANSITION_ENTER |
581 Geofence.GEOFENCE_TRANSITION_EXIT);
592 <code><a href="{@docRoot}reference/com/google/android/gms/location/Geofence.html">Geofence</a></code>
594 {@link android.content.Intent} that it sends to your app when it detects geofence
596 <h4>Define a Intent for geofence transitions</h4>
612 * app when a geofence transition occurs.
683 Mark this as a request to add a geofence by setting a global variable. This allows you to
702 // Stores the PendingIntent used to request geofence monitoring
719 * Start a request for geofence monitoring by calling
763 <code><a href="{@docRoot}reference/com/google/android/gms/location/LocationClient.html#addGeofences(java.util.List<com.google.android.gms.location.Geofence>, android.app.PendingIntent, com.google.android.gms.location.LocationClient.OnAddGeofencesResultListener)">LocationClient.addGeofences()</a></code>.
798 <code><a href="{@docRoot}reference/com/google/android/gms/location/LocationClient.html#addGeofences(java.util.List<com.google.android.gms.location.Geofence>, android.app.PendingIntent, com.google.android.gms.location.LocationClient.OnAddGeofencesResultListener)">addGeofences()</a></code>
935 "Geofence Detection");
943 Handle Geofence Transitions
945 <h2 id="HandleGeofenceTransitions">Handle Geofence Transitions</h2>
947 When Location Services detects that the user has entered or exited a geofence, it
954 notification when a geofence transition occurs. When the user clicks the notification, the
989 * of the geofence or geofences that triggered the transition
997 (transitionType == Geofence.GEOFENCE_TRANSITION_ENTER)
999 (transitionType == Geofence.GEOFENCE_TRANSITION_EXIT)
1001 List <Geofence> triggerList =
1007 // Store the Id of each geofence
1019 "Geofence transition error: " +
1042 explicit intents. How the incoming geofence transition intents are created is described in the
1048 <h2 id="StopGeofenceMonitoring">Stop Geofence Monitoring</h2>
1050 To stop geofence monitoring, you remove the geofences themselves. You can remove a specific
1075 specified by their geofence IDs, by the method
1236 The procedure for removing an individual geofence or set of geofences is similar to the
1237 removal of all geofences. To specify the geofences you want remove, add their geofence ID
1250 // Store the list of geofence Ids to remove
1255 <code><a href="{@docRoot}reference/com/google/android/gms/location/Geofence.html">Geofence</a></code>
1256 defined by the geofence ID "1":