Closed waterdrake closed 1 year ago
You should be able to do something along these lines:
WGS84Point location = new WGS84Point(/* users location */);
GeoHashCircleQuery query = new GeoHashCircleQuery(location, 100);
List<GeoHash> queryHashes = query.getSearchHashes();
/*
Now use the list of hashes generated (in string representation) to prefix query the rows in the database.
*/
After getting queryHashes
how do we get the actual hash out of it? is it geoHash.toString()
?
List<GeoHash> queryHashes = query.getSearchHashes();
for (GeoHash geoHash: queryHashes) {
geoHash.toString()
}
.toBase32()
is the method you might be looking for, if you store the base-32 encoded string as a field and want to use a prefix match. You can however only get the base-32 encoded string for multiples of 5 bits of precision (since each character encodes 5 bits).
Is there any sample code for how one might use this library with a NoSQL database such as DynamoDB?
I have a large number of NoSQL objects containing the geohash of the lat & long of restaurants that looks like this:
I want to be able to create a query where I can pass in the user's location as a geohash and return all restaurants in a 100 meter radius. I would like the results to be sorted so that the restaurants closest to the user appear at the top of the list.
So far, I understand that I can take the lat/long of a restaurant and turn it into a geohash like this:
GeoHash geoHash = GeoHash.withCharacterPrecision(lat, long, 12);
Then, I can use the same code to get the current position of the user:
GeoHash usersPosition = GeoHash.withCharacterPrecision(lat, long, 12);
I know that after this I need to make a query on my restaurants where I filter results based on the user's geohash. I know how to make such queries with my database code, but I am not sure how to use this library to help me.Could someone provide sample code on how to use this library to create my query? (pseudo code for the part where you query the NoSQL database is fine). I know there may be false-positives I need to account for as well, and throw them out. And that there may be multiple queries I need to make to my database.
This seems like a really good library, and I want to make sure I am using it right.