An architecture proposal for a geofencing API on Google's App Engine using Google Cloud Endpoints. This API is able to geofence complex polygons at a large throughput using App Engine, Cloud Datastore and Memcache. It uses the Java Topology Suite to create a spatial index which is stored in Memcache for fast querying access. You can download, build and deploy the project as is using the Google App Engine Maven plugin. For a detailed explanation of the architecture please refer to this Google Developers Blogpost.
- add: Add a fence to a certain group.
- buildIndex: Build the spatial index and write it to Memcache.
- getById: Get a fence's metadata by it's id.
- list: List all fences in a certain group.
- point: Get all fences that contain a certain point.
- polygon: Get all fences that aren't disjoint with a certain polygon.
- polyline: Get all fences that intersect with a certain polyline.
-
Update the value of
application
insrc/main/webapp/WEB-INF/appengine-web.xml
to the app ID you have registered in the App Engine admin console and would like to use to host your instance of this sample. -
Optional step: These sub steps are not required but you need this if you want to have auth protected methods.
-
Update the values in
src/main/java/com/google/appengine/geo/fencing/Constants.java
to reflect the respective client IDs you have registered in the APIs Console. -
You also need to supply the web client ID you have registered in the APIs Console to your client of choice (web, Android, iOS).
-
-
Run the application with
mvn appengine:devserver
, and ensure it's running by visiting your local server (by default localhost:8080.) -
Optional step: Get the client library with
$ mvn appengine:endpoints_get_client_lib
It will generate a client library jar file under the
target/endpoints-client-libs/<api-name>/target
directory of your project, as well as install the artifact into your local maven repository.For more information on client libraries see:
-
Deploy your application to Google App Engine with
$ mvn appengine:update
Please note that you should always first test on the development server since that creates indexes for our datastore queries. Also after the first deployment App Engine takes a while to create the necessary indexes and connections, so if you get errors, just wait for a bit.
Example of using the JavaScript Google Client Library with this API
-
src/main/webapp/addFence.html
is an example of how to use the Google Maps JavaScript API Drawing Layer to draw fences to the map and store them to your App Engines Datastore using the add endpoint. -
src/main/webapp/query.html
shows you how to query your API for points, polylines and polygons.
These examples can also be used to test your API. You should always first test on the devserver (mvn appengine:devserver
),
since this automatically creates indexes that are needed for our Datastore queries.