Android
-
Pass the location updates that were obtained from the Google Play services or the Android location services to the Places Extension.
-
Use the
getNearbyPointsOfInterest
Places Extension API to get the list ofPlacesPoi
objects around the current location.LocationCallback callback = new LocationCallback() { @Override public void onLocationResult(LocationResult locationResult) { super.onLocationResult(locationResult); Places.getNearbyPointsOfInterest(currentLocation, 10, new AdobeCallback<List<PlacesPOI>>() { @Override public void call(List<PlacesPOI> pois) { starMonitoringGeofence(pois); } }); } };
-
Extract the data from the obtained
PlacesPOI
objects and start monitoring those POIs.private void startMonitoringFences(final List<PlacesPOI> nearByPOIs) { // check for location permission for (PlacesPOI poi : nearByPOIs) { final Geofence fence = new Geofence.Builder() .setRequestId(poi.getIdentifier()) .setCircularRegion(poi.getLatitude(), poi.getLongitude(), poi.getRadius()) .setExpirationDuration(Geofence.NEVER_EXPIRE) .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT) .build(); geofences.add(fence); } GeofencingRequest.Builder builder = new GeofencingRequest.Builder(); builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER); builder.addGeofences(geofences); builder.build(); geofencingClient.addGeofences(builder.build(), geoFencePendingIntent) }
Calling the getNearbyPointsOfInterest
API results in a network call that gets the location around the current location.
IMPORTANT
You should call the API sparingly or only when there is significant location change of the user.