Select to view content in your preferred language

Introducing ArcGIS AppStudio New Sample: Geotrigger

2070
0
12-02-2021 01:29 PM
TrevorFrame
Esri Contributor
3 0 2,070

We are excited to announce with the new release of AppStudio 5.2, you now have access to ArcGIS Runtime 100.12 which includes the newly enhanced Geotrigger API. In this blog post you will learn what geotriggers are and how to build a mobile app that uses them with your own data. All you need is to download AppStudio Desktop 5.2 and AppStudio Player app. 

What is a geotrigger? 

A geotrigger allows you to monitor real-time GIS data and receive notifications when a specified condition is met such as when a device enters or leaves an area.  

This technology has many applications and is already used in our lives daily. Delivery apps use this to alert their customers when the delivery drivers are nearing their drop off location and some GPS services alert drivers when they are coming up to a traffic condition like an accident or reported police officer sighting. Some other areas of possible use could be: 

  • Alerts for underwater oil pipeline 
  • Mine vehicle collision alerts 
  • Alerts for underground utility lines 
  • Information tourism 
  • Alerting field workers of danger zones 
  • Alerting users in unauthorized areas 

How to download and run the geotriggers sample app 

To experience geotriggers, we’ve created a sample app called Geotrigger. This sample mobile app can be found and ran with either AppStudio Desktop or AppStudio Player 5.2 and above on an iOS, Android, Windows, MacOS, and Ubuntu device.  

To see the sample using AppStudio Desktop, open AppStudio Desktop (5.2 or above), click the New App button, and browse for the app under the Samples tab or use the search box to find it by title and click Create. Once the sample app has been created, you can click Run in AppStudio Desktop, or click Edit to open the code in your editor of choice and run it there.  

To see the sample using AppStudio Player, open AppStudio Player (5.2 or above). If not already done so, enable developer mode by selecting your profile icon in the top left corner. Select App Settings, then toggle Developer Mode. Go back to the home screen, and you will notice a new bottom tab with a compass icon. Selecting this tab opens the Samples screen where you can preview all AppStudio sample apps. You can scroll or use the search function to find the sample to preview.  

About the geotrigger sample app 

There are two samples within this application. One uses a simulated path that travels through Santa Barbara Botanic Gardens and another uses your current device's location and the OpenStreetMap Medical Facilities for North America feature layer. 

When first opening the application, the Simulated Device sample will appear, and the simulated device will start moving through the Santa Barbara Botanic Gardens map. There are two features within this map, garden sections and garden points of interests. When within a feature geotrigger monitor parameter buffer, the geotrigger monitor will trigger a notification and populate a Garden Section or Point of Interest button. You can click the button to see some of that feature information pulled by the geotrigger monitor from the feature layer. 

SampleBlogPost-Simulated.gif

The Current Device Location sample will use your current device's location and the OpenStreetMap Medical Facilities feature layer stated above. Features within a set distance radius will be queried. After moving half the radius distance, features will be queried again based on the new current location. Just like the other sample, once your location is within the geotrigger monitor buffer, medical facilities buttons will appear. Clicking on the buttons will open a pane displaying the facility’s available information. This sample mobile app is intended for experiencing geotriggers while roaming the real world with a mobile device. So, get up, get out, and start moving towards these local medical facilities.  

SampleBlogPost-CurrentLocation.gif

How geotriggers work 

Once a map with features and a location display with a data source have been set up, a geotrigger monitor can be created. In the monitor, you will set what location data source and features to monitor, what event type triggers it (enter, exit, or enter and exit), a feature buffer distance, a message expression (what info is received from the feature layer), and a signal handler, onGeotriggerNotification, is called when the event trigger occurs. To learn more about geotriggers, check out the ArcGIS Runtime API for Qt, Work with Geotriggers, and the runtime QML sample, Set up location-driven Geotriggers 

Some important things to note 

  • You may use multiple GeotriggerMonitors, one for each feature layer. 
  • When there are too many features within a layer (typically more than 2000), the GeotriggerMonitor may fail to build. A fix for this can be to use a definitionExpression to limit the total rendered features before the GeotriggerMonitor is started. 

How to use your own data 

After trying out the available sample app, you can create an app with geotriggers and your own data by following the steps below. 

  1. Create your map and/or feature layers if needed. 
  2. Replace the ServiceFeatureTable PortalItem itemIds to point to your feature layers.  
  3. Add any additional service feature tables if needed 
  4. For each additional feature table, add another GeotriggerMonitor 
  5. Add the feature table id to the GeotriggerMonitor's fenceParameter. 
  6. If your feature layer has more than 2000 features, you can set up query parameters to limit the number of features to render and monitor. 
    1. This will be used to query all features within a buffer radius 
  7. After the map has been loaded, query all features within a radius using the findFeaturesWithinRadius() function.  
  8. After querying the features, in the signal handler of the service feature table, onQueryFeaturesStatusChanged, take all features queried and create a definition expression to render only the features queried within the buffer radius. 
  9. After setting the definition expression, start the geotrigger monitor.  
  10. This makes it so the geotrigger monitor can build with few features. 
  11. In the GeotriggerMonitor’s messsageExpression, replace “objectid” to a unique field name that best identifies your features. 
  12. To get the feature layer data, in the GeotriggerMonitor onGeotriggerNotification signal, change the fence geo attribute values (eg, “name”) you want to retain.  

Geotriggers are a fun and very useful tool that can be used for many different things. They help provide insightful information pertaining to location and can provide a sense of urgency when utilized correctly. We hope you learned what geotriggers are and are inspired to use them. Please feel free to share with us how you used geotriggers in your next projects.   

Acknowledgements 

Credit: © OpenStreetMap contributors 

OpenStreetMaps data is used for sample purposes only and not intended for commercial use. It is a live replica of the OpenStreetMap database, and the feature layer is licensed under the same Open Database License (ODbL). Please refer to OpenStreetMaps Terms of Use for details on how to use their data. 

About the Author
Product Engineer working with AppStudio to build cross platform mobile applications.