Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistencies with onTransitionReceived() #293

Open
cathrinerathje opened this issue Apr 10, 2019 · 0 comments
Open

Inconsistencies with onTransitionReceived() #293

cathrinerathje opened this issue Apr 10, 2019 · 0 comments

Comments

@cathrinerathje
Copy link

I'm creating an Ionic app in which I use geofences to read information aloud about sights the user passes, and also to read guidance instructions (like Google Maps) for the user along the route.

Therefore I have two types of geofences - sights with radius 100m and directions with radius 50m. They are being added in the exact same way, and the addOrUpdate() method is succesful in both cases. However, only the directions geofences are being registered by onTransitionReceived().

The directions geofences are being created from an array of directions received from a Google DirectionsService response. The sights geofences are being created from an array of sights retrieved from a previous page in the app.
The only way I can make it work for the sights geofences is if I first format the properties I need into an array and then create and add the fences from it.
This seems very strange to me since the added geofences look identical when printed to the console.

Here is how I do it:

In constructor:

geofence.removeAll().then(()=>{ console.log('all geofences removed'), (err)=>{ console.log(err); } });

geofence.initialize().then(()=>{ console.log('geofence plugin ready'), (err)=>{ console.log(err); } });

Adding geofences in .ts file:

`
private addSightGeofences() {
let fences = [];

this.sights.map((sight, index) => {
  let fence = {
    id: 's' + index,
    latitude: sight.lat,
    longitude: sight.lng,
    radius: 100,
    transitionType: 1,
    notification: {
      id: index,
      title: 'You crossed a sight',
      text: 'You just arrived at '+ sight.name,
      openAppOnClick: true,
      data: {
        isSight: true,
        sightName: sight.name,
        originalName: sight.originalName,
        text: sight.longDescription
      }
    }
  }
  fences.push(fence);
});

this.geofence.addOrUpdate(fences).then(()=>{
  console.log('sight geofence added'),
  (err) =>{
    console.log('geofence failed to add')
  }
});

}
`

`addDirectionsGeofences() {
let fences = [];

this.directions.map((step, index) => {
  let fence = {
    id: 'd' + index,
    latitude: step.lat,
    longitude: step.lng,
    radius: 50,
    transitionType: 1,
    notification: {
      id: index,
      title: 'You reached a direction',
      text: 'You just arrived at '+ step.instructions,
      openAppOnClick: true,
      data: {
        isSight: false,
        instructions: step.instructions,
        value: step.value
      }
    }
  }
  fences.push(fence);
});

this.geofence.addOrUpdate(fences).then(()=>{
  console.log('directions geofence added'),
  (err) =>{
    console.log('geofence failed to add')
  }
});

}`

Then the call to onTransitionReceived() also in .ts file:

addGeofenceTransitions() { this.geofence.onTransitionReceived().subscribe((res) => { console.log(res); res.forEach((f) => { console.log(f); if (f.notification.data.isSight == true) { console.log('sight geofence reached'); this.sightSpeech(f.notification.data); this.updateDirectionsGeofences(); } else { console.log('directions geofence reached'); this.directionsSpeech(f.notification.data.instructions, f.notification.data.value); } }); }); console.log('geofence transitions added'); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant