Swiftpack.co - ualch9/GeohashKit as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by ualch9.
ualch9/GeohashKit v2.0
Swift multi-platform Geohash implementation
⭐️ 0
🕓 4 weeks ago
.package(url: "https://github.com/ualch9/GeohashKit.git", from: "v2.0")



GeohashKit is a native Swift implementation of the Geohash hashing algorithm. Supporting encode, decode and neighbor search.

The original Swift (v1) implementation is from maximveksler/GeohashKit. The v2 implementation uses a data structure to define the Geohash as a rectangular cell, rather than just a string.


  • iOS, macOS, watchOS, tvOS
  • Ubuntu

API (v2)

A Geohash is a data structure, representing a geohash as a rectangular cell.

Initialize with coordinates ("Encode")

let geohash = Geohash(coordinates: (42.6, -5.6), precision: 5)
print(geohash.geohash)      // "ezs42"

Initialize with existing geohash ("Decode")

let geohash = Geohash(geohash: "ezs42")
print(geohash.coordinates)  // (latitude: 42.60498046875, longitude: -5.60302734375)


let neighbors = Geohash(geohash: "u000").neighbors  // Returns an array of neighbor geohash cells.
print(neighbors.north)                              // Get the north (top) cell.
print(geohash.neighbors.all.map { $0.geohash })     // ["u001", "u003", "u002", "spbr", "spbp", "ezzz", "gbpb", "gbpc"]


let geohash = Geohash(geohash: "ezs42")
let region: MKCoordinateRegion = geohash.region

Re: Precision

I purposely left out a precision enum. I found that explaining the approximate size of the cell at a given precision was confusing, it is difficult to explain a size without using numbers (case 2500km is not valid Swift). Geohashes are rectangular Mercator cells with true size dependent on the latitude, so defining a case twentyFiveHundredKilometers is still not necessarily true.

v1 API (maximveksler/GeohashKit compatible) To use the maximveksler-compatible API, checkout exactly `1.0`:
.package(url: "https://github.com/ualch9/geohashkit.git", .exact("1.0"))


Geohash.encode(latitude: 42.6, longitude: -5.6) // "ezs42"

Specify desired precision

Geohash.encode(latitude: -25.382708, longitude: -49.265506, 12) // "6gkzwgjzn820"


Geohash.decode("ezs42")! // (latitude: 42.60498046875, longitude: -5.60302734375)

Neighbor Search

Geohash.neighbors("u000")! // ["u001", "u003", "u002", "spbr", "spbp", "ezzz", "gbpb", "gbpc"]


Use Swift Package Manager.


MIT License.


Stars: 0
Last commit: 4 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Related Packages

Release Notes

4 weeks ago
  • Add MapKit extensions

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics