Skip to content

Instantly share code, notes, and snippets.

@blangel
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save blangel/9758633 to your computer and use it in GitHub Desktop.

Select an option

Save blangel/9758633 to your computer and use it in GitHub Desktop.
// The GeoQueryRequest will contain the inputted QueryRequest (decorated with geo-hash/etc)
// as well as a QueryResultGeoFilter to post process the results
GeoQueryRequst geoQueryRequest = geo.radiusQuery(QueryRequest request, double latitude, double longitude, double radius, Config config);
QueryRequest queryRequest = geoQueryRequest.queryRequest;
// clients will use GeoQueryRequest in a manner similar to the following
List<Map<String, AttributeValue>> resultItems = new ArrayList<Map<String, AttributeValue>>((limit < 1000 ? limit : 1000));
do {
try {
queryResult = ddb.query(queryRequest);
} catch (ResourceNotFoundException rnfe) {
// queryRequest not found, simply break
break;
}
List<Map<String, AttributeValue>> items = queryResult.getItems();
// filter the results using the geo filter
List<Map<String, AttributeValue>> filteredItems = geoQueryRequest.queryResultGeoFilter.filter(items);
resultItems.addAll(filteredItems);
queryRequest = queryRequest.withExclusiveStartKey(queryResult.getLastEvaluatedKey());
} while ((queryResult.getLastEvaluatedKey() != null) && (resultItems.size() < limit));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment