radshag / PhoneGap-Geofencing

Geofencing Plugin For Phonegap
95 stars 56 forks source link

ios: I am not getting notify when exiting a region #36

Open i25878427 opened 10 years ago

i25878427 commented 10 years ago

Hello,

I am trying to create region monitor, I wrote the code below but it doesn't alert me when the region is being exit.

When I run my code, a "initmonitor" alert is popup (as it should) and after clicking on the "foo" button, I received "startmonitor" alert. Then in my xcode simulator I change the simulation location to a different city, and I expected to get exit region alert but it doesn't popup.

*I am using phonegap 3.1.0-0.15.0

I will appreciate if you can help me.

Thanks, Roy

```
      <script type="text/javascript" src="cordova.js"></script>
<!--script type="text/javascript" src="js/index.js"></script-->
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
<script type="text/javascript" src="lib/DGGeofencing.js"></script>

 <script type="text/javascript" src="cordova.ios.js"></script>

<script type="text/javascript">
    document.addEventListener('deviceready', onDeviceReady, false);
    // deviceready Event Handler`
    function onDeviceReady() {
        DGGeofencing.initCallbackForRegionMonitoring(new Array(), processRegionMonitorCallback, function(error) {
             console.log("init error");
         });
    }
processRegionMonitorCallback = function(result) {
    alert(result.callbacktype)
}
function foo(){

 var location = new Object();
 location.id ="111";
 location.location = new Object();
 location.location.lat = "32.0833"
 location.location.lng = "34.8000"

 var params = [location.id, location.location.lat, location.location.lng, "10", "3"];
 DGGeofencing.startMonitoringRegion(params, function(result) {alert(result)}, function(error) {
        alert("failed to add region");
 });

}
</script>
radshag commented 10 years ago

I would not recommend testing the app in this way. You should deploy the app to a device that supports geofencing and test from there

From: i25878427 Sent: ‎Saturday‎, ‎22‎ ‎March‎ ‎2014 ‎17‎:‎36 To: radshag/PhoneGap-Geofencing

Hello,

I am trying to create region monitor, I wrote the code below but it doesn't alert me when the region is being exit.

When I run my code, a "initmonitor" alert is popup (as it should) and after clicking on the "foo" button, I received "startmonitor" alert. Then in my xcode simulator I change the simulation location to a different city, and I expected to get exit region alert but it doesn't popup.

I will appreciate if you can help me.

Thanks, Roy

    <button onclick="foo()">foo</button>
</div>
      <script type="text/javascript" src="cordova.js"></script>
<!--script type="text/javascript" src="js/index.js"></script-->
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
<script type="text/javascript" src="lib/DGGeofencing.js"></script>

 <script type="text/javascript" src="cordova.ios.js"></script>

<script type="text/javascript">
    document.addEventListener('deviceready', onDeviceReady, false);
    // deviceready Event Handler`
    function onDeviceReady() {
        DGGeofencing.initCallbackForRegionMonitoring(new Array(), processRegionMonitorCallback, function(error) {
             console.log("init error");
         });
    }
processRegionMonitorCallback = function(result) {
    alert(result.callbacktype)
}
function foo(){

 var location = new Object();
 location.id ="111";
 location.location = new Object();
 location.location.lat = "32.0833"
 location.location.lng = "34.8000"

 var params = [location.id, location.location.lat, location.location.lng, "10", "3"];
 DGGeofencing.startMonitoringRegion(params, function(result) {alert(result)}, function(error) {
        alert("failed to add region");
 });

}
</script>

— Reply to this email directly or view it on GitHub.

i25878427 commented 10 years ago

thanks for replying. I tested it on my iphone 5 and it doesn't work. When I am using the example provided with the plugin, the "exit region" alert does work on my xcode simulator and also on my iphone.

radshag commented 10 years ago

Do you get an enter region event when entering. On Mar 22, 2014 11:38 PM, "i25878427" notifications@github.com wrote:

thanks for replying. I tested it on my iphone 5 and it doesn't work. When I am using the example provided with the plugin, the "exit region" alert does work on my xcode simulator and also on my iphone.

Reply to this email directly or view it on GitHubhttps://github.com/radshag/PhoneGap-Geofencing/issues/36#issuecomment-38364961 .

i25878427 commented 10 years ago

Thanks for helping, I found out why it was not working. the reason was that i hard coded the latitude and longitude- I attached the working example below.

```
      <script type="text/javascript" src="cordova.js"></script>
<!--script type="text/javascript" src="js/index.js"></script-->
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
<script type="text/javascript" src="lib/DGGeofencing.js"></script>

 <script type="text/javascript" src="cordova.ios.js"></script>

<script type="text/javascript">
    var latitude;
    var longitude;
    document.addEventListener('deviceready', onDeviceReady, false);
    // deviceready Event Handler`

    function onDeviceReady() {
        DGGeofencing.initCallbackForRegionMonitoring(new Array(), processRegionMonitorCallback, function(error) {
             console.log("init error");
         });

         navigator.geolocation.getCurrentPosition(onGeoSuccess, onGeoError, { maximumAge: 600000, timeout: 5000, enableHighAccuracy: true });
     }
    processRegionMonitorCallback = function(result) {
        alert(result.callbacktype)
    }

function onGeoSuccess(position){
    latitude = position.coords.latitude;
    longitude = position.coords.longitude;
    var location = new Object();
    location.id ="111";
    location.location = new Object();
    location.location.lat = latitude
    location.location.lng = longitude

    var params = [location.id, location.location.lat, location.location.lng, "10", "3"];
    DGGeofencing.startMonitoringRegion(params, function(result) {alert(result)}, function(error) {
                                       alert("failed to add region");
                                       });

}
function onGeoError(error){

}