Database Reference
In-Depth Information
Query radius
Similar to what we saw in the Query rectangle section. Amazon gives us an API that can
list all items present in the radius of a certain circle drawn from a given geo point. Here,
the inputs to the API are the center geo point and the radius of the circle in which you
need to find items. The following is how the syntax of the query radius looks:
// center geo point
GeoPoint centerGeoPoint = new GeoPoint(18.514973,
73.850698);
// create query radius request
QueryRadiusRequest radiusRequest = new QueryRadiusRequest(
centerGeoPoint, 200);
// invoke query result method
QueryRadiusResult radiusResult = geoDataManager
.queryRadius(radiusRequest);
// Get items from the result
for (Map<String, AttributeValue> item :
radiusResult.getItem()) {
System.out.println("Item :" + item);
}
This would print all geo points that are in the 200-metre radius of the given center point.
Internally, when we insert a geo point into DynamoDB, the geo hash gets calculated, and
this geo hash is used to uniquely and exactly identify the location of geo points on planet
Earth. This library also stores the geo hash as a separate attribute of an item. Hash stores
the proximity of a nearby point, and for efficient retrieval it is stored as a local secondary
index on items.
You can find examples of how to use this library on GitHub at https://github.com/awslabs/
dynamodb-geo/tree/master/samples .
Search WWH ::




Custom Search