Skip to content

Repository files navigation

GitHub license Maven Central Version Kotlin Kotlin Multiplatform

badge-android badge-ios badge-desktop badge-js

Geohash Multiplatform

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.

Features

Dave lists several features on his project page, but I'll just paraphrase the important one's here:

  • Full Multiplatform Library. It should compile on any platform.
  • encodes a geohashes from a latitude & longitude, with a length from 1 to 12
  • decodes a latitude, longitude from a geohashes
  • finds an adjacent hash in cardinal directions, and works on borders including the poles.
  • can find all 8 adjacent hashes
  • calculates hash length to enclose a bounding box
  • calculates geohashes of given length to cover a bounding box, wih ratios.
  • can calculate the height and width of a geohashe in degrees
  • encodes & decodes Long values from geohashes

Installation

Maven Central Version

implementation("io.github.aughtone:geohash:${version}")

Quick Start

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)

Feedback

Bugs can go into the issue tracker, but you are probably going to get faster support by creating a PR.


🤖 AI-Assisted Development

This library includes embedded, machine-readable "skills" to enhance the experience of developers using AI code assistants. These skills help the AI understand our library's APIs and best practices, leading to more accurate and idiomatic code suggestions.

  • AI Skill Discovery: Look for META-INF/ai-skills/*.ai-skill.md

To learn how to add this capability to your own library, see our AI Skill Publishing Standard.

About

A pure kotlin port of a geohash library set up for kotlin multiplatform.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages