Testing the Geofencing API

Etienne Lawlor
Sep 12, 2015 · 3 min read

The existing set of tools to test the Geofencing API are lacking and hopefully Google will someday fill this void. This is how I tested the Geofencing API.


Genymotion

I installed the latest Genymotion (Android emulator) , setup a new virtual device in Genymotion and booted up the new device. I believe most Genymotion devices don’t come pre-installed with Google Play Services or Google Apps (specifically Google Maps) so I followed this StackOverflow post How to install Google Play Services in Genymotion to get that set up. I had to drag and drop the ARM Translation Installer and the Google Apps .zip files onto the new Genymotion device. At this point you probably will need to reboot the Genymotion device and sign in to your Google account. An update to Google Maps and Google Play Services may be required in the Google Play Store on the device. Now you should be all set up with a Genymotion device and the latest version of the Google Maps app.


Download Geofencing Sample Project

The latest Geofencing sample app from Google is at this repo Google Play Location Samples. So do a :

git clone https://github.com/googlesamples/android-play-location

in your local workspace. I use Android Studio for development, so to import the Geofencing sample, File > Open > /android-play-location/Geofencing (the path to the Geofencing project) . Now run the Geofencing project in Android Studio and choose to run on the Genymotion device you already have up and running. Once it is up and running click the ADD GEOFENCES button. Your geofences have now been created. Close this sample app and open the Google Maps app.


Simulate Location Changes

In order to simulate changes to the devices location you need to execute shell commands in the Genymotion Shell. This ruby script will help simulate those changes (Geofencing Simulator). I also had to add the Genymotion shell to my path

export PATH=$PATH:/Applications/GenymotionShell.app/Contents/MacOS

To run the ruby script you need to execute it in a bash shell like

$ ruby gpx_trip.rb /path/to/gpx_trip.gpx

The final piece to this is generating a .gpx file that maps out a route. To do this you just create a route from point A to point B . Since the two geofences in the sample are the Googleplex and the Yerba Buena Gardens, I have created a route that goes back and forth between these two locations (Geofencing route) . Then you can take this url and paste it into this GPSVisualizer tool(Convert a GPS file to plain text or GPX) and click on Convert. This will generate the .gpx file that you see on the next page (GPX output) . Copy those contents and paste it into a new file that you create called gpx_trip.gpx . As soon as you execute the ruby script you should now see the blue dot on the Google Maps app start moving in the map. Subsequently when you enter and exit the geofences then a notification will appear in the notification drawer indicating entering or exiting a geofence. This all is a bit verbose but I wanted to make sure I didn’t miss anything. Hopefully this will all be a bit easier in the future.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade