Language: HTML | XAML

Geofencing, start to finish (XAML)

Applies to Windows and Windows Phone

Geofencing is a new feature in Windows 8.1 that allows an app to define a geographical region and have the system alert the app when the device it's running on enters or exits that area.

With geofencing, your app can send a reminder to a user who is leaving work or arriving home. By setting up a series of geofences, you could display coupons whenever the user is near a coffee shop. Using cloud services like Azure Mobile Services, you could also create an app that notifies you when friends are nearby.

To use a geofence in your app, you'll first need to define a Geofence, then set up an event handler to listen for events, and finally, handle those events once they occur.

If you're new to developing Windows Store apps using C++, C#, or Visual Basic, take a look at Create your first Windows Store app using C# or Visual Basic to get up to speed.

Set up your geofences

start icon

You can start by reviewing the geolocation API's. The Quickstart: detecting a user's location topic will show how to get the user's location. The How to respond to location updates topic will show how to get continuous updates on location changes.

step icon

Next you can review some best practices for working with geofences. These Guidelines for geofencing can help you make decisions about the design of your app and how you can incorporate geofencing into it.

One important decision will be to decide if your app will handle the geofence events in the foreground while your app is running or if you will set up a background task and then handle the event when the background trigger is fired.

These guidelines can also help you decide on the number and size of the geofences you want to create.

step icon

Quickstart: setting up a geofence

Once you have reviewed the best practices, you can set up one or more geofences. You'll also want to be sure the user has enabled the location permissions, in order to receive any geofence events.

 

Handling geofence notifications in the foreground

step icon

Quickstart: handling geofence notifications in the foreground

If you want to process geofence events in the foreground while your app is running, then you can add the event handlers to handle what happens when a geofence is entered, exited, or removed.

 

Listening for geofence events in the background

step icon

Quickstart: listening for geofence events in the background

On the other hand, if you want to set up a background task to handle the geofence events, you must follow a number of steps to make sure your app is set up and configured by the user to work in the background.

 

Handling geofence notifications from a background task

step icon

Quickstart: handling geofence notifications from a background task

If you've reviewed the Guidelines for geofencing and decided to set up a background task for your geofences, then you need to handle the events when they are triggered. This code will allow you to alert the user that a geofence event has occurred.

 

Testing and debugging your geofencing apps

step icon

Testing and debugging your geofencing apps

Once you have completed your geofencing app, you can use a variety of tools to test and debug it.

 

Want to know more?

Now that you have seen how geofencing works, here is some more info on related topics.

Windows Store app UI, start to finish (XAML)

Learn more about designing Windows Store app UI.

Roadmap for Windows Runtime apps using C# and Visual Basic and Roadmap for Windows Runtime apps using C++

Learn more about creating Windows Store apps using C++, C#, or Visual Basic in general.

Designing UX for apps

Learn more about designing great user experiences.

How to display your location using Bing Maps

Learn how to detect the user's current location and display it on a map.

Guidelines for location-aware apps

Learn about some best practice for your location-aware app.

 

 

Show:
© 2014 Microsoft