También puede utilizar sus servicios de supervisión e integrarse con el servicio de lugares mediante las API de extensión de lugares.
Si decide utilizar sus servicios de monitoreo, registre las geofences de los puntos de interés en su ubicación actual siguiendo estos pasos:
En iOS, complete los siguientes pasos:
Pase las actualizaciones de ubicación obtenidas de los servicios de ubicación principales de iOS a la extensión Places.
Utilice la API de extensión getNearbyPointsOfInterest
Places para obtener la matriz de ACPPlacesPoi
objetos alrededor de la ubicación actual.
- (void) locationManager: (CLLocationManager*) manager didUpdateLocations: (NSArray<CLLocation*>*) locations {
[ACPPlaces getNearbyPointsOfInterest:currentLocation limit:10 callback: ^ (NSArray<ACPPlacesPoi*>* _Nullable nearbyPoi) {
[self startMonitoringGeoFences:nearbyPoi];
}];
}
Extraiga la información de los ACPPlacesPOI
objetos obtenidos y el inicio que supervisa dichos puntos de interés.
- (void) startMonitoringGeoFences: (NSArray*) newGeoFences {
// verify if the device supports monitoring geofences
// check for location permission
for (ACPPlacesPoi * currentRegion in newGeoFences) {
// make the circular region
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(currentRegion.latitude, currentRegion.longitude);
CLCircularRegion* currentCLRegion = [[CLCircularRegion alloc] initWithCenter:center
radius:currentRegion.radius
identifier:currentRegion.identifier];
currentCLRegion.notifyOnExit = YES;
currentCLRegion.notifyOnEntry = YES;
// start monitoring the new region
[_locationManager startMonitoringForRegion:currentCLRegion];
}
}
Pase las actualizaciones de ubicación obtenidas de los servicios Google Play o de los servicios de ubicación de Android a Places Extension.
Utilice la getNearbyPointsOfInterest
API de extensión de lugares para obtener la lista de PlacesPoi
objetos en la ubicación actual.
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);
}
});
}
};
Extraiga los datos de los PlacesPOI
objetos obtenidos y el inicio que supervisa dichos puntos de interés.
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)
}
Al llamar a la getNearbyPointsOfInterest
API se produce una llamada de red que obtiene la ubicación alrededor de la ubicación actual.
Debe llamar a la API con moderación o solo cuando haya un cambio significativo en la ubicación del usuario.
En iOS, llame a la API de processGeofenceEvent
lugares en el CLLocationManager
delegado. Esta API le notifica si el usuario ha entrado o salido de una región específica.
- (void) locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
[ACPPlaces processRegionEvent:region forRegionEventType:ACPRegionEventTypeEntry];
}
- (void) locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
[ACPPlaces processRegionEvent:region forRegionEventType:ACPRegionEventTypeExit];
}
En Android, llame al processGeofence
método junto con el evento de transición adecuado en el receptor de difusión de Geofence. Es posible que desee depurar la lista de geofences recibidas para evitar entradas/salidas de duplicado.
void onGeofenceReceived(final Intent intent) {
// do appropriate validation steps for the intent
...
// get GeofencingEvent from intent
GeofencingEvent geoEvent = GeofencingEvent.fromIntent(intent);
// get the transition type (entry or exit)
int transitionType = geoEvent.getGeofenceTransition();
// validate your geoEvent and get the necessary Geofences from the list
List<Geofence> myGeofences = geoEvent.getTriggeringGeofences();
// process region events for your geofences
for (Geofence geofence : myGeofences) {
Places.processGeofence(geofence, transitionType);
}
}