项目作者: drfonfon

项目描述 :
Android Kotlin GeoHash library
高级语言: Kotlin
项目地址: git://github.com/drfonfon/android-kotlin-geohash.git
创建时间: 2018-07-30T10:44:01Z
项目社区:https://github.com/drfonfon/android-kotlin-geohash

开源协议:

下载


Android-Kotlin-Geohash

An implementation of Geohashes in Android.
The produced hashes, when using character precision (multiples of 5 bits) are compatible to the reference implementation geohash.org.

Include gradle dependency

Add it in your root build.gradle at the end of repositories:

  1. allprojects {
  2. repositories {
  3. ...
  4. maven { url 'https://jitpack.io' }
  5. }
  6. }

Add the dependency:

  1. dependencies {
  2. implementation 'com.github.drfonfon:android-kotlin-geohash:1.0'
  3. }

Creation examples

  1. val location = Location("geohash");
  2. location.latitude = 53.2030476;
  3. location.longitude = 45.0324948;
  4. val hashFromLaLo = GeoHash(53.2030476, 45.0324948)//"v12n8trdjnvu"
  5. val hashFromLaLoAndCharSize = GeoHash(53.2030476, 45.0324948, 8)//"v12n8trd"
  6. val hashFromLocation = GeoHash(location)//"v12n8trdjnvu"
  7. val hashFromLocationAndCharSize = GeoHash(location, 8)//"v12n8trd"
  8. val hashFromString = GeoHash("v12n8trd")
  9. "v12n8trd".toGeoHash()
  10. location.toGeoHash()//"v12n8trdjnvu"
  11. location.toGeoHash(8)//"v12n8trd"

Methods

  1. val location = Location("geohash");
  2. location.latitude = 53.2030476;
  3. location.longitude = 45.0324948;
  4. val hash = GeoHash(location, 8)//"v12n8trd"
  5. //Get base32 string value
  6. hash.toString()//"v12n8trd"
  7. //get next incremented geoHash
  8. hash.inc()//"v12n8trdk"
  9. //get previous decremented geoHash
  10. hash.dec()//"v12n8trdh"
  11. //get next geoHash from step
  12. hash.next(2) //"v12n8trdm"
  13. //get adjacent - N, NE, E, SE, S, SW, W, NW geoHashes
  14. hash.adjacent //"v12n8trdm", "v12n8trdq", "v12n8trdn", "v12n8tr9y", "v12n8tr9v", "v12n8tr9u", "v12n8trdh", "v12n8trdk"
  15. //get adjacent boxed - NW, N, NE, W, CENTER, E , SW, S, SE geoHashes
  16. hash.adjacentBox //"v12n8trdk", "v12n8trdm", "v12n8trdq", "v12n8trdh", "v12n8trdj", "v12n8trdn", "v12n8tr9u", "v12n8tr9v", "v12n8tr9y"
  17. //get geoHash childs
  18. hash.childs() //"v12n8trdj0", "v12n8trdj1", "v12n8trdj2", "v12n8trdj3", "v12n8trdj4", "v12n8trdj5", "v12n8trdj6", "v12n8trdj7", "v12n8trdj8", "v12n8trdj9", "v12n8trdjb", "v12n8trdjc", "v12n8trdjd", "v12n8trdje", "v12n8trdjf", "v12n8trdjg", "v12n8trdjh", "v12n8trdjj", "v12n8trdjk", "v12n8trdjm", "v12n8trdjn", "v12n8trdjp", "v12n8trdjq", "v12n8trdjr", "v12n8trdjs", "v12n8trdjt", "v12n8trdju", "v12n8trdjv", "v12n8trdjw", "v12n8trdjx", "v12n8trdjy", "v12n8trdjz"
  19. //get geoHash parents
  20. hash.parent() // "v12n8trd"
  21. hash.northernNeighbour //"v12n8trdm"
  22. hash.southernNeighbour //"v12n8tr9v"
  23. hash.easternNeighbour //"v12n8trdn"
  24. hash.westernNeighbour //"v12n8trdh"