查找附近的人-geohash使用方法

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

发布了54 篇原创文章 · 获赞 13 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/liutaiyi8/article/details/84527395