Usar seu próprio monitor using-your-monitor
Você também pode usar os serviços de monitoramento e integrar com o Places Service usando as APIs da extensão Places.
Registrando Geofences
Se decidir usar seus serviços de monitoramento, registre as geofences dos POIs em torno de sua localização atual seguindo as etapas abaixo:
iOS
No iOS, conclua as seguintes etapas:
-
Passe as atualizações de localização obtidas dos Serviços principais de localização da iOS para a extensão Places.
-
Use a API de extensão do Places
getNearbyPointsOfInterest
para obter a matriz de objetosACPPlacesPoi
em torno do local atual.code language-objective-c - (void) locationManager: (CLLocationManager*) manager didUpdateLocations: (NSArray<CLLocation*>*) locations { [ACPPlaces getNearbyPointsOfInterest:currentLocation limit:10 callback: ^ (NSArray<ACPPlacesPoi*>* _Nullable nearbyPoi) { [self startMonitoringGeoFences:nearbyPoi]; }]; }
-
Extraia as informações dos objetos
ACPPlacesPOI
obtidos e comece a monitorar esses POIs.code language-objective-c - (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]; } }
Android
-
Transmita as atualizações de localização obtidas dos serviços da Google Play ou dos serviços de localização da Android para a Extensão do Places.
-
Use a API de Extensão do Places
getNearbyPointsOfInterest
para obter a lista de objetosPlacesPoi
em torno do local atual.code language-java 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); } }); } };
-
Extraia os dados dos objetos
PlacesPOI
obtidos e comece a monitorar esses POIs.code language-java 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) }
Chamar a API getNearbyPointsOfInterest
resulta em uma chamada de rede que obtém a localização ao redor da localização atual.
Publicação de eventos de geofence
iOS
No iOS, chame a API do Places processGeofenceEvent
no delegado CLLocationManager
. Essa API notifica se o usuário entrou ou saiu de uma região 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];
}
Android
No Android, chame o método processGeofence
junto com o evento de transição apropriado em seu receptor de transmissão Geofence. Convém preparar a lista de geofences recebidos para evitar entradas/saídas duplicadas.
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);
}
}