radarlabs / react-native-radar

React Native module for Radar, the leading geofencing and location tracking platform
https://radar.com
Apache License 2.0
170 stars 32 forks source link

Need to leave the geofence and re-enter it for it to be triggered #28

Closed feargswalsh92 closed 6 years ago

feargswalsh92 commented 6 years ago

I am trying to use the Radar API I want the app to refresh nearby places results as the user moves. I have set up a geofence that is triggered every time the user loads my app and creates a circular geofence around their location. However, as it stands events will not be triggered on the geofence unless the user leaves the area and then re-enters. Or if the app is reloaded. Is there any way to trigger a user.entered_geofence event every time a new Geofence is set up? Here's my api call

export const createNewGeofence = (location) => {
  return new Promise((resolve, reject) => {
    fetch(geofenceURL, {
      method: 'post',
      headers: {
        'Authorization': testApiKey,
        'Accept': 'application/json',
        'Content-Type': 'application/json'

      },
      body: JSON.stringify({
        description: description,
        type: type,
        radius: radius,
        userid: userid,
        coordinates: location,
        enabled: enabled
        // latitude, longitude
      })
    }).then((response) => {
      if (response.status === 200) {
        resolve(response.json())
      } else {
        reject(response.statusText ? response.statusText : response.status)
      }
    }).catch(error => error)
  })
}
russellcullen commented 6 years ago

Unfortunately there is no way to generate events when creating geofences at the moment. In fact, this is expected behavior. The way the events are processed requires a user update request to generate any events. If you have the SDK install you can call trackOnce() after creating the geofence and you should receive an event (if the user is entered of course).