This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ApiMethod(name = "add", httpMethod = "post", path = "add") | |
public MyFence addFence(@Named("group") String group, @Named("index") boolean buildIndex, MyFence fence) { | |
//Get the last fences' id. | |
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); | |
Key fenceKey = KeyFactory.createKey("Geofence", group); | |
long nextId; | |
if (fence.getId() != -1) { | |
nextId = fence.getId(); | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Build the index. | |
index.build(); | |
//Write the index to Memcache. | |
MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService(); | |
//Last param is expiration date. Set to null to keep it in Memcache forever. | |
syncCache.put(group, index, null); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Get all fences of group from DataStore. | |
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); | |
Key fenceKey = KeyFactory.createKey("Geofence", group); | |
Query query = new Query("Fence", fenceKey).addSort("id", Query.SortDirection.DESCENDING); | |
List < Entity > fencesFromStore = datastore.prepare(query).asList(FetchOptions.Builder.withDefaults()); | |
if (!fencesFromStore.isEmpty()) { | |
//Create STRTree-Index. | |
STRtree index = new STRtree(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.google.appengine.geo.fencing; | |
/** The object model for the data we are sending through endpoints */ | |
public class MyFence { | |
private long id = -1; | |
public String name; | |
public String entityGroup; | |
public String description; | |
public double[][] vertices; |
NewerOlder