https://github.com/fummicc1/geohashswift
yet another GeoHash implementation written in Swift
https://github.com/fummicc1/geohashswift
geohash public swift
Last synced: 7 months ago
JSON representation
yet another GeoHash implementation written in Swift
- Host: GitHub
- URL: https://github.com/fummicc1/geohashswift
- Owner: fummicc1
- License: mit
- Created: 2024-11-16T03:33:42.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-02-02T01:49:24.000Z (8 months ago)
- Last Synced: 2025-03-18T13:48:49.009Z (7 months ago)
- Topics: geohash, public, swift
- Language: Swift
- Homepage:
- Size: 59.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GeoHashSwift
GeoHashSwift is a Swift implementation of GeoHash.
[GeoHashCLI](https://github.com/user-attachments/assets/4d19753f-dc6e-4d26-bdce-14b9963f2dde)
## Installation & Usage
### GeoHashFramework
GeoHashFramework is a framework that ships things to calculate GeoHash from coordinates.
You can use it as a dependency of your project.
```swift
dependencies: [
.package(url: "https://github.com/fummicc1/GeoHashSwift.git", from: "0.0.4")
]
``````swift
import GeoHashFrameworklet geoHash = GeoHash(latitude: 35.681382, longitude: 139.766084, precision: .mid)
print(geoHash.geoHash) // "xn76urwe"
```### GeoHashCLI
GeoHashCLI executable is a CLI tool which depends on GeoHashFramework.
You can use this executable to generate GeoHash from coordinates.
- Install via Homebrew
```sh
brew tap fummicc1/geohash
brew install fummicc1/geohash/geohash
```Usage:
```sh
# Generate GeoHash from latitude and longitude
geohash 35.681236 139.767125
> xn76urx6
# Generate GeoHash from coordinate2d
geohash --coordinate "35.681236,139.767125"
> xn76urx6
```- Install via Swift Package Manager
```swift
dependencies: [
.package(url: "https://github.com/fummicc1/GeoHashSwift.git", from: "0.0.4")
]
```Usage:
```sh
# Generate GeoHash from latitude and longitude
swift run geohash 35.681236 139.767125
> xn76urx6
# Generate GeoHash from coordinate2d
swift run geohash --coordinate "35.681236,139.767125"
> xn76urx6
```## APIs
### Models
#### GeoHash
A GeoHash is a GeoHash object.
You can obtain both binary and hex values of coordinate from GeoHash object.
More implementation related to Coordinate2D (latitude, longitude) is in GeoHashCoordinate2D.swift.
Beside the calculation of GeoHash, this object also provides the followings:
- a method to get bounds of the GeoHash.
- a method to get neighbors of the GeoHash with bits precision same.#### GeoHashCoordinate2D
A GeoHashCoordinate2D represents a pair of latitude and longitude in binary.
**Note that actual latitude and longitude are not stored in this object, because the accuracy of GeoHash is not guaranteed.**
### Features
- User can generate GeoHash from:
- latitude and longitude
- binary string
- GeoHash string
- User can retrieve hash string from `GeoHash` object.
- User can obtain bounds of GeoHash.
- User can obtain neighbors of GeoHash.## Related Repositories
- [GeoHashDebugView: An example app using GeoHashSwift](https://github.com/fummicc1/GeoHashDebugView)