我一直在到处搜索有关如何使用ch.hsr.geohash搜索附近位置的清晰示例。我的意思是,我只需要实现以下情况:

1-我有一个经度和纬度。
2-将此纬度/经度转换为哈希。 (我相信这是通过使用“ GeoHash.withBitPrecision(纬度,经度,64)”完成的,但是我不确定这里的精度是多少。我想64位将具有与
3-检索100公里范围内的纬度/经度列表(我什至不知道如何使用geohash来启动它)
4-使用纬度/经度结果列表查询对象化对象。

但是我找不到关于lib的任何文档,也没有任何清晰的示例。
请有人给我建议或给我任何起点进行搜索吗?是否有人已经使用此库来达到我正在寻找的相同结果?
非常感谢!

最佳答案

我以以下方法结束:

Geohash geohash = Geohash。 withCharacterPrecision(latitude,经度,12);
字符串geohashString = geohash.toBase32();

然后根据我想要的距离使用geohashString。我的意思是,根据字符串的精度匹配字符串的前缀。例如,

数据库:

Name | geohash | id

Model 1 | gc7x9813vx2r | 1
Model 2 | gc7x8840suhr | 2
Model 3 | gc30psvp0zgr | 3


然后,我想获得所有距离该点半径100公里以内的模型(53.244664,-6.140530)。

Geohash geohash = Geohash. withCharacterPrecision(53.244664, -6.140530, 12);
String geohashString = geohash.toBase32().substring(0, 3); //3 characters for around 100km of precision

ofy().load().type(Model.class).filter("geohash >=", geoHashString).filter("geohash <", geoHashString + "\uFFFD");


然后,它将仅匹配以“ gc7”开头的模型1和模型2,因此它们大约在100 km半径之内。

出于精度考虑,请遵循此表:
https://en.wikipedia.org/wiki/Geohash

实际上,我可以简化以下步骤:

String geohashString = Geohash. withCharacterPrecision(53.244664, -6.140530, 3).toBase32();


我还没有进行任何性能测试,但我认为它不会变慢得多。无论如何,如果性能测试“失败”,我将实现相同的功能,但使用binaryString代替。

10-08 12:38