Created
September 8, 2016 04:34
-
-
Save rakhimoni/ff7fe14016dbb96ba27022ced3759da5 to your computer and use it in GitHub Desktop.
EnterRegions event on iOS Geofence module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Geofence = require("ti.geofence"); | |
| var window = Ti.UI.createWindow({ | |
| backgroundColor: 'white' | |
| }); | |
| var titleInWinA = Ti.UI.createLabel({ | |
| text: 'Receiving location ... ', | |
| left: 70, | |
| top: 100, | |
| }); | |
| window.add(titleInWinA); | |
| window.addEventListener("open", function() { | |
| checkLocationPermissions(); | |
| }); | |
| function checkLocationPermissions() { | |
| if (!Ti.Geolocation.hasLocationPermissions()) { | |
| Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS, function(e) { | |
| if (!e.success) { | |
| Ti.API.error("Error requesting location permissions: " + e.error); | |
| return; | |
| } | |
| getCurrentPosition(); | |
| }); | |
| } else { | |
| getCurrentPosition(); | |
| } | |
| } | |
| function getCurrentPosition() { | |
| Ti.Geolocation.getCurrentPosition(function(e) { | |
| if (e.error) { | |
| alert('Error: ' + e.error); | |
| } else { | |
| Enterregions(e.coords.latitude, e.coords.longitude); | |
| } | |
| }); | |
| } | |
| function Enterregions(latitude, longitude) { | |
| Ti.API.info(latitude + '\n' + longitude); | |
| titleInWinA.setText(latitude + '\n' + longitude); | |
| var newRegion = Geofence.createRegion({ | |
| center: { | |
| latitude: latitude, | |
| longitude: longitude | |
| }, | |
| radius: 500, | |
| identifier: 'Appcelerator' | |
| }); | |
| Geofence.startMonitoringForRegions([newRegion]); | |
| Geofence.addEventListener("enterregions", function(e) { | |
| Ti.API.info('####### enterregion #######: ' + JSON.stringify(e)); | |
| alert('enter region fired'); | |
| }); | |
| Geofence.addEventListener("monitorregions", function(e) { | |
| Ti.API.info('####### monitorregions #######: ' + JSON.stringify(e)); | |
| }); | |
| } | |
| window.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment