geo-fencing image

A geo-fence is a virtual perimeter that maps over some geographic point or object in the real world. These digitally generated spaces can be used in conjunction with your location aware device to produce alerts and behaviors as follows:

  • Request to be notified when the device enters a geo-fence.
  • Request to be notified when the device leaves a geo-fence.
  • Specify a time window during which the geo-fence is active.
  • Specify a dwell time for each geo-fence (amount of time that the device should be in or out of an area).

The use-cases even for this partial list is quite large in both a professional and personal context, however, one of the best applications I heard of was at the Kenya Wild Life Service. “Near threatened” bull elephants were constantly leaving a conservation park and terrorizing local farmers, one particular elephant (Kimani) had a particularly long history of raiding crops…

The race to save Kimani began two years ago. The Kenya Wildlife Service had already reluctantly shot five elephants from the conservancy who refused to stop crop-raiding, and Kimani was the last of the regular raiders. The Save the Elephants group wanted to see if he could break the habit.

So they placed a mobile phone SIM card in Kimani's collar, then set up a virtual "geofence" using a global positioning system that mirrored the conservatory's boundaries. Whenever Kimani approaches the virtual fence, his collar texts rangers.

They have intercepted Kimani 15 times since the project began. Once almost a nightly raider, he last went near a farmer's field four months ago.

This topic applies to many location aware devices, but I will be covering the shared API that applies to Windows hardware (phones, tablets and laptops).

Windows.Devices.Geolocation.Geofencing Namespace

The Geofence class is the main construct for defining a geo-fence, it contains data points that define its shape and duration. The Geocircle is currently the only shape supported but, it is implemented as an interface which could support any shape you saw fit to create. The Geofence class is in turn supported by GeofenceMonitor, its primary task is to manage and assess the state of your defined geo-fences, and the following shows that in action.

private void CreateGeofence(double lat, double lng, double rad)
{
var position = new BasicGeoposition
{
Latitude = lat,
Longitude = lng
};

var circle = new Geocircle(position, rad);
var mask = MonitoredGeofenceStates.Entered | MonitoredGeofenceStates.Exited;
var dwellTime = TimeSpan.FromHours(24);

var geofence = new Geofence(Guid.NewGuid().ToString(), circle, mask, false, dwellTime);

GeofenceMonitor.Current.Geofences.Add(geofence);
}

Foreground Geofencing Detection

Once a geo-fence is created and stored we need a mechanism to respond to a breach in its boundaries, in the following code sample we accomplish this task in the foreground directly within the page of an app:

using Windows.UI.Core;
using Windows.UI.Popups;
using Windows.Devices.Geolocation.Geofencing;


namespace PhoneApp1
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
Windows.Devices.Geolocation.Geofencing.GeofenceMonitor.Current.GeofenceStateChanged
+= Current_GeofenceStateChanged;

}

async void Current_GeofenceStateChanged(Windows.Devices.Geolocation.Geofencing.GeofenceMonitor sender,
object args)
{
var reports = sender.ReadReports();

await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
foreach (GeofenceStateChangeReport report in reports)
{
var state = report.NewState;
var geofence = report.Geofence;

if (state == GeofenceState.Entered)
{
var dialog = new MessageDialog(String.Format("Entered GeoFence {0}, your dwell time is {1}",
geofence.Id, geofence.DwellTime), "Entering A GeoFence");
await dialog.ShowAsync();
}
else if (state == GeofenceState.Exited)
{
var dialog = new MessageDialog(String.Format("Exited GeoFence {0}, your dwell time is {1}",
geofence.Id, geofence.DwellTime), "Exit A GeoFence");
await dialog.ShowAsync();
}
}
});

}

}
}

Security & Privacy

When developing apps that use geo-fencing technologies developers have a fiduciary responsibility to treat this data with extreme caution and care. A user's geographic location is personally identifiable information (PII). At a minimum you should do the following:

  • Get the users consent.
  • Tell the user how location data will be used.
  • Clear all cached location data when the user disables access to location info.


Related Posts

July 16, 2014 2:53    Comments [0]
Tagged in API | Windows | Windows Phone

Share on Twitter, Facebook and LinkedIn


Earlier this year I spent significant time with a vendor troubleshooting requests we were sending across the network. In the end I was convinced of my need to rely almost exclusively on the vendor to verify that the certificate were correctly applied. Well, a colleague shared this link that describes how to configure network tracing for WCF service.

Configure Network Tracing

<configuration>
<system.diagnostics>
<sources>
<source name="System.Net" tracemode="includehex" maxdatasize="1024">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
<source name="System.Net.Cache">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
<source name="System.Net.Http">
<listeners>
<add name="System.Net "/>
</listeners>
</source>
<source name="System.Net.Sockets">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
<source name="System.Net.WebSockets">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
</sources>
<switches>
<add name="System.Net" value="Verbose"/>
<add name="System.Net.Cache" value="Verbose"/>
<add name="System.Net.Http" value="Verbose"/>
<add name="System.Net.Sockets" value="Verbose"/>
<add name="System.Net.WebSockets" value="Verbose"/>
</switches>
<sharedListeners>
<add name="System.Net"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="network.log"
/>
</sharedListeners>
<trace autoflush="true"/>
</system.diagnostics>
</configuration>

When troubleshooting complex systems never trust the well intentioned opinion of even the savviest technical mind, get the facts. This would have saved me days!

Related Posts

July 14, 2014 22:03    Comments [0]
Tagged in .NET | WCF

Share on Twitter, Facebook and LinkedIn


I was an early adopter for Windows 8, I used prerelease version, Windows 8 and am now happily on Windows 8.1. While I am successfully negotiating the the hybrid operating systems my non technical family continue to struggle with what they saw as standard operations under Windows 7 (printing, scanning, etc). Just yesterday I watched as a relative struggled to print from the modern version of Internet Explorer just because that was the version Windows 8 presented in that scenario.

My sincere advise to Microsoft is that the next release of Windows should be context sensitive. If I am using a mouse allow me the benefit of the highly efficient and speedy desktop mode, especially if I have not a single  touch enabled device attached. If I am on a touch centric device with no mouse feel free to foist onto to my experience all the advantages of the Metro UI family, along with its well intentioned Metro offspring (IE, Photos, Mail, etc).

As it currently stands I am forced to either teach folks two ways to work or reject the Modern/Metro way entirely and simply make the desktop experience (with it desktop shortcuts and the pinned tasks bar) the only valid choice.

July 3, 2014 2:25    Comments [0]
Tagged in Windows

Share on Twitter, Facebook and LinkedIn


googledrive

Back in 2012 Google acquired Quickoffice and this purchased allowed for one of the highlights of the I/O keynote address, that is,  bringing native Office editing to its Google Docs cloud service.  Additionally Google Drive for Work is being sold at $10 a month, and provides unlimited storage capabilities (the timing of Microsoft's Office 365 storage increase was no coincidence).

It is clear that Google is making a significant and strategic play on Microsoft’s core enterprise business, this strategy is perfectly sound but I am fascinated how the marketing department feel about the idea of using compatibility with a rival as a selling point. Surely that immediately labels you as the “other” and any discussion about your service is ultimately never on your own terms. Those guys are smarter than me I am sure they will figure it out, but core identity is a tricky thing and inherently positioning your self in the shadow of an already dominant product is a losing proposition IMHO.

June 25, 2014 19:58    Comments [1]
Tagged in Cloud Services | Microsoft

Share on Twitter, Facebook and LinkedIn


Today, OneDrive and Office are announcing a BIG change to that benefit for consumers, to the tune of 1 TB per user. That’s right–we’re increasing the OneDrive storage allotment included with Office 365 Home, Office 365 Personal, and Office 365 University from 20 GB to 1 TB. That’s a whopping 50 times, or 5,000 percent increase in storage–and it’s going to be here before classes are in session!

Office 365 One Drive Storage


Wow! This is excellent, I am also interested in seeing if there an increase in the size of the files that you are able to upload (which is currently limited to 1.5GB). Let the cloud disk space wars continue!

Related Posts

June 23, 2014 15:44    Comments [0]
Tagged in Cloud Services

Share on Twitter, Facebook and LinkedIn