Geofencing is the application of a virtual perimeter around a real-world geographic area. Using GPS or radio frequency identification (RFID), this location-based service can be used in fleet management to alert the dispatcher when a driver breaks from his route. It also has applications in law enforcement, where ankle bracelets alert the authorities if the wearer leaves the predefined locale, and it encompasses many other applications.
In marketing, for example, geofencing could be used to deliver targeted promotions directly to consumers’ mobile devices as they move around a shopping mall. Devices distributed throughout the mall could monitor when a shopper (and their mobile phone) cross a boundary into a geofenced area, such as a particular shop. Automated processes can then send store-specific coupons directly to that shopper’s device with deals on items in that store.
This hyper-local marketing tactic drives consumer engagement by leveraging their location, thanks to geofencing techniques. In this tutorial, Thorsten Schaeff on the Google Developers Blog guides followers through building a scalable but affordable geofencing API using Google’s App Engine, starting with the Java Backend API Tutorial, which uses Apache Maven to manage and build the project.
The architecture involves the storing, indexing, and serving of complex fences (represented as polygons) along with some metadata for each one. After followers have added additional libraries to the project, they are guided through writing the endpoints to add fences to the Cloud Datastore. This is followed by retrieving the list of fences, getting a fence’s metadata by its ID, and building the spatial index.
The tutorial ends on testing a latitude/longitude point to determine if it is within one of your fences, followed by testing fences against polylines or polygons, and finally deploying to the App Engine. Code and all relevant links are provided, including a link to the finished, downloadable geofencing API on GitHub.