I'm currently working on an app that triggers a notification when someone is within a square. The following defines the square:
var zonebounds = [[30,35], [40,45]];
var zone = L.rectangle(zonebounds, {color: "#ff7800", weight: 1, oppacity: .5});
I've made the following statement to check if someone is within the square.
if (posY > zonebounds[0][0] && posY < zonebounds[1][0] && posX > zonebounds[0][1] && posX < zonebounds[1][1] && zoneTimer == 0) {
ons.notification.toast('Test', { timeout: 5000 });
zoneTimer = 1;
} else if (posY >! zonebounds[0][0] && posY <! zonebounds[1][0] && posX >! zonebounds[0][1] && posX <! zonebounds[1][1] && zoneTimer == 1) {
zoneTimer = 0;
}
I think >!
sadly doesn't behave as I would like it to.
I've made the zoneTimer variable so that the notification doesn't repeat itself. Maybe there is an even better way to do this.
Update
I fixed it by using a combination of the two answers I got, here is the final result:
if(zoneBoundslatLng.contains(latLng)){
if (inZone == 0) {
inZone = 1;
ons.notification.toast('Zone 1, klik voor informatie.', { timeout: 5000 });
}
} else {
inZone = 0;
}