Select to view content in your preferred language

How to implement geofence using ArcGIS javascript api

5841
2
11-16-2015 03:29 AM
absarhasan
New Contributor

I have created a map using  ArcGIS​​ javascript api, and searching for geofencing implementation with javascript api for Cordova application with notification on enter/out in geofence area but not found any related document. Is there any way to implement geofencing using javascript apis? any example? documentation?

0 Kudos
2 Replies
ChrisSmith7
Frequent Contributor

You should probably check-out the GeoTrigger API:

Geotrigger API Reference | ArcGIS for Developers

Here's the service homepage:

Geotrigger Service | ArcGIS for Developers

0 Kudos
absarhasan
New Contributor

Yes I have used javascript geotrigger apis for creating geofence like sample code

var geo = geotriggers.request("trigger/create", {

                condition: {

                    direction: "enter",

                    geo: {

                        latitude: evt.result.feature.geometry.getLatitude(),

                        longitude: evt.result.feature.geometry.getLongitude(),

                        distance: $scope.radius

                    }

                },

                action: {

                    notification: {

                        text: "Welcome to my world"

                    }

                },

                setTags: ["device:" + geotriggers.deviceId]

            }, function(error, response, xhr) {

                console.log(response);

                //var radius = 2000;

                var circle = new Circle({

                    center: [result.getLongitude(), result.getLatitude()],

                    geodesic: true,

                    radius: $scope.radius

                            //radiusUnit: "esriMiles"

                });

                var circleSymb = new SimpleFillSymbol(

                        SimpleFillSymbol.STYLE_SOLID,

                        new SimpleLineSymbol("solid", new Color([232, 104, 80]), 2),

                        new Color([232, 104, 80, 0.25])

                        );

                var graphicc = new Graphic(circle, circleSymb);

                map.graphics.add(graphicc);

                geotriggers.request("location/last", {

                    //tags: ["portland", "trigger:0a40d32c822f6fa15e3bb255a03867f1"],

                    //triggerIds:['0a40d32c822f6fa15e3bb255a03867f1'],

                    //"deviceIds":['bBpZcWnu5l3xb0dl']

                }, function(error, response, xhr) {

                    console.log(error, response, xhr);

                });

                geotriggers.request("trigger/run", {

                    tags: ["device:" + geotriggers.deviceId]

                }, function(error, response, xhr) {

                    console.log(error, response, xhr);

                });

            });

and then notify the updated status using

geotriggers.request("device/notify",

                    {

                        // dryRun: true,

                        "tags": ["device:" + geotriggers.deviceId],

                        "geo": {

                            "latitude": 18.50897704100,

                            "longitude": 73.82487596500052

                        },

                        "deviceIds": [geotriggers.deviceId]

                    },

            function(error, response, xhr) {

                console.log(error, response, xhr);

                // alert(JSON.stringify(response));

            });

but here after I am not able to find any document for implementation in map and get notification when it breaks geofence.

There are steps for android and ios with SDK  but not found any for javascript for hybrid mobile implementation.

And at last I want to be confirmed that is gefencing if posiible using javascript apis?

0 Kudos