geohash已有java的封装:
1,导入geohash的jar包
<dependency>
<groupId>ch.hsr</groupId>
<artifactId>geohash</artifactId>
<version>1.3.0</version>
</dependency>
2,使用方法:
2.1 将经纬度转为geocode编码(通过对比code的精度位数的到具体范围内的位置)
lat:纬度坐标
lon: 经度坐标
precision: 要生成的编码的长度 最大为十二位
GeoHash geoHash = GeoHash.withCharacterPrecision(lat, lon, precision);
String binaryCode = geoHash.toBinaryString(); // 使用给定的经纬度坐标生成的二进制编码
2.2 如何取出具体范围内的位置
geohash的精度范围:
具体表示为:我当前坐标的code与目标坐标code对比前5位相同,那我们在4.9km范围内。直接使用sql语句 like