-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from michael-groble/add-implementation
Add implementation
- Loading branch information
Showing
10 changed files
with
463 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,4 @@ | ||
# Xcode | ||
# | ||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore | ||
|
||
## Build generated | ||
build/ | ||
DerivedData/ | ||
|
||
## Various settings | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
xcuserdata/ | ||
|
||
## Other | ||
*.moved-aside | ||
*.xcuserstate | ||
|
||
## Obj-C/Swift specific | ||
*.hmap | ||
*.ipa | ||
*.dSYM.zip | ||
*.dSYM | ||
|
||
## Playgrounds | ||
timeline.xctimeline | ||
playground.xcworkspace | ||
|
||
# Swift Package Manager | ||
# | ||
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. | ||
# Packages/ | ||
.build/ | ||
|
||
# CocoaPods | ||
# | ||
# We recommend against adding the Pods directory to your .gitignore. However | ||
# you should judge for yourself, the pros and cons are mentioned at: | ||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control | ||
# | ||
# Pods/ | ||
|
||
# Carthage | ||
# | ||
# Add this line if you want to avoid checking in source code from Carthage dependencies. | ||
# Carthage/Checkouts | ||
|
||
Carthage/Build | ||
|
||
# fastlane | ||
# | ||
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the | ||
# screenshots whenever they are needed. | ||
# For more information about the recommended setup visit: | ||
# https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md | ||
|
||
fastlane/report.xml | ||
fastlane/Preview.html | ||
fastlane/screenshots | ||
fastlane/test_output | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
os: | ||
- linux | ||
- osx | ||
language: generic | ||
sudo: required | ||
dist: trusty | ||
osx_image: xcode8 | ||
script: | ||
- eval "$(curl -sL https://swift.vapor.sh/ci)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "Geohash" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,48 @@ | ||
# Geohash | ||
[![Build Status](https://api.travis-ci.org/michael-groble/Geohash.svg?branch=master)](https://travis-ci.org/michael-groble/Geohash) | ||
|
||
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). | ||
|
||
```swift | ||
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). | ||
|
||
```swift | ||
GeohashBits(hash: "u10hfr2").boundingBox().center() | ||
=> (longitude: 0.0995635986328125, latitude: 51.5004730224609) | ||
``` | ||
|
||
This is the same answer you will get from PostGIS | ||
|
||
```sql | ||
select ST_AsText(ST_PointFromGeoHash('u10hfr2')); | ||
st_astext | ||
-------------------------------------------- | ||
POINT(0.0995635986328125 51.5004730224609) | ||
``` | ||
|
||
The library also supports computing neighbors | ||
|
||
```swift | ||
GeohashBits(hash: "u10hfr2c4pv").neighbor(.north).hash() | ||
=> "u10hfr2c60j" | ||
``` | ||
|
||
## Acknowledgements | ||
Based on the [Redis implementation](https://github.com/antirez/redis/blob/unstable/src/geohash.c), | ||
* Copyright (c) 2013-2014, yinqiwen <yinqiwen@gmail.com> | ||
* Copyright (c) 2014, Matt Stancliff <matt@genges.com> | ||
* Copyright (c) 2015-2016, Salvatore Sanfilippo <antirez@gmail.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// BoundingBox.swift | ||
// Geohash | ||
// | ||
// Created by michael groble on 1/6/17. | ||
// | ||
// | ||
|
||
public class BoundingBox { | ||
let min: Location | ||
let max: Location | ||
|
||
public init(min: Location, max: Location) { | ||
self.min = min | ||
self.max = max | ||
} | ||
|
||
public func center() -> Location { | ||
return Location( | ||
longitude: 0.5 * (self.min.longitude + self.max.longitude), | ||
latitude: 0.5 * (self.min.latitude + self.max.latitude) | ||
) | ||
} | ||
} |
Oops, something went wrong.