Uploaded image for project: 'Appcelerator Modules'
  1. Appcelerator Modules
  2. MOD-2419

Android: Ti.Geofence module's "enterregions" event does not execute at the entry point but a few minutes later on Android.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: None
    • Resolution: Not Our Bug
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Geofence
    • Labels:
    • Environment:

      Description

      Issue overview:
      I implemented the ti.geofence modules for some features of automatic opening of gates while you are driving, so from app closed or in the background. In the implementation for iOS the functionality works well.
      For Android, the "enterregions" event of the module is executed not at the entry point but a few minutes later, when you are already closer to the coordinates of the center of the region. I am using version 3.0.0 of the ti.geofence module with Titanium SDK 7.1.0.

      Test Code:

      var Geofence = require("ti.geofence");
       
      //Set the latitude and longitude here
      var lat = 23.802592;
      var lon = 90.361040;
       
      var window = Ti.UI.createWindow({
          backgroundColor: 'white'
      });
       
      var titleInWinA = Ti.UI.createLabel({
          left: 70,
          top: 100,
      	text: "Initializing test-case ..."
      });
      window.add(titleInWinA);
       
      window.addEventListener("open", function() {
          checkLocationPermissions();
      });
       
      function checkLocationPermissions() {
          if (!Ti.Geolocation.hasLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS)) {
              Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS, function(e) {
                  if (!e.success) {
                      Ti.API.error("Error requesting location permissions: " + e.error);
                      return;
                  }
       
      			Enterregions();
              });
          } else {
          	Enterregions();
          }
      }
       
      function getCurrentPosition() {
          Ti.Geolocation.getCurrentPosition(function(e) {
              if (e.error) {
                  alert('Error: ' + e.error);
              } else {
                  Enterregions(e.coords.latitude, e.coords.longitude);
              }
          });
      }
       
      function Enterregions(l) { 
          var newRegion = Geofence.createRegion({
              center: {
                  latitude: lat,
                  longitude: lon
              },
              radius: 500,
              identifier: 'Grameen'
          });
       
          Geofence.startMonitoringForRegions([newRegion]);
       
          Geofence.addEventListener("enterregions", function(e) {
              Ti.API.info('####### enterregion #######: ' + JSON.stringify(e));
      		titleInWinA.setText(titleInWinA.text+"\n"+"enter region fired!");
              alert('enter region fired');
          });
      	
         Geofence.addEventListener("exitregions", function(e) {
             Ti.API.info('####### exitregion #######: ' + JSON.stringify(e));
      	   titleInWinA.setText(titleInWinA.text+"\n"+"exit region fired!");
             alert('exit region fired');
         });
       
          Geofence.addEventListener("monitorregions", function(e) {
              Ti.API.info('####### monitorregions #######: ' + JSON.stringify(e));
      		titleInWinA.setText(titleInWinA.text+"\n"+"monitoring regions");
          });
      }
      window.open();
      

      Steps to reproduce:
      1. Set the latitude and longitude in the sample code.
      2. Run the code and observe that when entering the area, enterregions event for Android runs in delay.

      Expected:
      The enterregions for android should fire at the entry point.

      Actual:
      It fires a few minutes later, not at the entry point.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ybanev Yordan Banev
                Reporter:
                jnaher Jebun Naher
              • Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • It looks like Backbone Issue Sync is not enabled for your project.

                    Git Source Code