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