Coder Social home page Coder Social logo

jceaser / geohash Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 4 KB

A horrible hack implementation of the GeoHash algorithm (which generates a hash from a lat/long) going on nothing but the most basic of understanding from how wikipedia described the algorithm going in the opposite direction (Hash to lat/lon) to generate a Hash.

License: MIT License

Swift 100.00%
geohash swift hack

geohash's Introduction

GeoHash

A horrible (way to much magic here (hardcoded values)) hack implementation of the GeoHash algorithm to generates a hash from a lat/long based on on nothing but the most basic of understanding from how wikipedia described the algorithm going in the opposite direction (Hash to lat/lon).

Unit Testing results

g.parse(lat:42.6, long: -5.6) == "ezs42"
g.parse(lat:-25.382708, long: -49.265506)=="6gkzwgjzn820"
g.parse(lat: 37.785834, long: -122.406417) == "9q8yywdq7vbp"
g.parse(lat:-25.383, long:-49.266) == "6gkzwgjt"
g.parse(lat:-25.427, long: -49.315) == "6gkzmg1u"
g.parse(lat:39.2780150, long:-76.7618450) == "dqcrmnrep2ev"
g.parse(lat:30.2672, long:-97.7431) == "9v6kpvcxh"

Magic

I would like to apologize to the world for this, really, but it's not all my fault.

Hash Codes

I did not even try to figure out the pattern, I just hard coded a table to convert numbers (left) to codes (right):

"10" = "b", "11" = "c", "12" = "d", "13" = "e", "14" = "f"
"15" = "g", "16" = "h", "17" = "j", "18" = "k", "19" = "m"
"20" = "n", "21" = "p", "22" = "q", "23" = "r","24" = "s"
"25" = "t", "26" = "u", "27" = "v", "28" = "w", "29" = "x"
"30" = "y", "31" = "z"

Precision

So I'm not sure how people connect precision of decimal places to hash length, and my algorithm required a number of iterations anyways, so I just fudged it Edison style (I can hear Tesla telling me that a little math would have saved me some time. See "fault" above.

g.guessPrecision(raw: 42.6) == 14
g.guessPrecision(raw: -25.383) == 20
g.guessPrecision(raw: 30.2672) == 22
g.guessPrecision(raw: -25.382708) == 32

License

I may change the license, so clone at your own risk.

geohash's People

Contributors

jceaser avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.