
Multiplatform library encodes and decodes geohashes from latitude and longitude, calculates bounding boxes, and finds adjacent hashes. Supports geohash operations like encoding Long values.
This library for set up for Kotlin Multiplatform (KMP)
This is a pure Kotlin port of Dave Moten's geo Java project. I think Dave may have ported it to Java from Dave Troy's geohash-js Javascript project.
Kotlin structures are not the same as Java, and this code was almost a decade old when I started this port, so quite a lot of refactoring will need to be done to make it all rainbows and sunshine for Kotlin developers.
Feel free to fork it and make improvements, I'll keep up as best I can.
Dave lists several features on his project page, but I'll just paraphrase the important one's here:
implementation("io.github.aughtone:geohash:${version}")You can use a Coordinate object, or a pair of Double values to generate a geohash from.
val location: Coordinate = Coordinate(latitude = 20.05, longitude = -15.5)
val geohash = location.toGeohash(4)To generate a geohash with a maximum length:
val geohash:String = stringGeohashOf(coordinate = location)You can also specify the length of the geohash you want to generate:
val geohash:String = stringGeohashOf(coordinate = location, length = 6)
You can work with an encoded geohash. The lambda must return either the same geohash or a modified version:
val checkCoordinate: Coordinate = Coordinate(latitude = 20.05, longitude = -15.5)
val myGeohash = stringGeohashOf(latitude = 20.05, longitude = -15.5, length = 6)
val myOther = geohash(myGeohash) { geohash ->
if(geohash contains checkCoordinate) {
it.southOf()
}else{
geohash adjacent Direction.TOP
}
}
You can also access the geohash object directly. In fact, until I refactor this a little more, that will be the only way to access some of the functions:
val myGeohash = stringGeohashOf(latitude = 20.05, longitude = -15.5, length = 6)
val data : List<String> = Geohash.neighbours(myGeohash)Bugs can go into the issue tracker, but you are probably going to get faster support by creating a PR.
This library for set up for Kotlin Multiplatform (KMP)
This is a pure Kotlin port of Dave Moten's geo Java project. I think Dave may have ported it to Java from Dave Troy's geohash-js Javascript project.
Kotlin structures are not the same as Java, and this code was almost a decade old when I started this port, so quite a lot of refactoring will need to be done to make it all rainbows and sunshine for Kotlin developers.
Feel free to fork it and make improvements, I'll keep up as best I can.
Dave lists several features on his project page, but I'll just paraphrase the important one's here:
implementation("io.github.aughtone:geohash:${version}")You can use a Coordinate object, or a pair of Double values to generate a geohash from.
val location: Coordinate = Coordinate(latitude = 20.05, longitude = -15.5)
val geohash = location.toGeohash(4)To generate a geohash with a maximum length:
val geohash:String = stringGeohashOf(coordinate = location)You can also specify the length of the geohash you want to generate:
val geohash:String = stringGeohashOf(coordinate = location, length = 6)
You can work with an encoded geohash. The lambda must return either the same geohash or a modified version:
val checkCoordinate: Coordinate = Coordinate(latitude = 20.05, longitude = -15.5)
val myGeohash = stringGeohashOf(latitude = 20.05, longitude = -15.5, length = 6)
val myOther = geohash(myGeohash) { geohash ->
if(geohash contains checkCoordinate) {
it.southOf()
}else{
geohash adjacent Direction.TOP
}
}
You can also access the geohash object directly. In fact, until I refactor this a little more, that will be the only way to access some of the functions:
val myGeohash = stringGeohashOf(latitude = 20.05, longitude = -15.5, length = 6)
val data : List<String> = Geohash.neighbours(myGeohash)Bugs can go into the issue tracker, but you are probably going to get faster support by creating a PR.