Swiftpack.co - Package - michael-groble/Geohash


Build Status

Native Swift geohash package supporting binary and character encoding

Geohashes are represented internally as 64 bit integers. A hash can be constructed either using character precision (up to 12 characters) or binary precision (up to 32 bits per angle).

GeohashBits(location: Location(longitude: -0.1, latitude: 51.5), characterPrecision: 12).hash()
=> "gcpuvxr1jzf"
GeohashBits(location: Location(longitude: -0.1, latitude: 51.5), bitPrecision: 26).hash()
=> "gcpuvxr1jz" 

Note that the last value is truncated at 10 characters (50 bits) even though the "full" representation is 52 bits total. Since the character encoding is Base32, we require 5 bits for each.

The Geohash boundaries and centroids are correctly handled when the character representation provides a different number of bits for latitude and longitude (e.g. geohash 7 which has 18 bits of longitude and 17 bits of latitude).

GeohashBits(hash: "u10hfr2").boundingBox().center()
=> (longitude: 0.0995635986328125, latitude: 51.5004730224609)

This is the same answer you will get from PostGIS

select ST_AsText(ST_PointFromGeoHash('u10hfr2'));
POINT(0.0995635986328125 51.5004730224609)

The library also supports computing neighbors

GeohashBits(hash: "u10hfr2c4pv").neighbor(.north).hash()
=> "u10hfr2c60j"


Based on the Redis implementation,


Stars: 1
Help us keep the lights on


Used By



0.5.0 - Jan 14, 2017

Adds geohash iterator

0.4.0 - Jan 9, 2017

add public bit-based initializer

0.3.0 - Jan 8, 2017

add intersection test to BoundingBox

0.2.0 - Jan 8, 2017

  • Fix property access
  • Add location tests

0.1.0 - Jan 8, 2017

initial implementation