Skip to content

creasty/geohash_ruby

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Geohash

Geohash en/decode library written in Ruby.

Install

gem 'geohash_ruby'

Usage

Encode latitude and longitude into geohash

Geohash.encode 47.6062095, -122.3320708
#=> "c23nb62w20st"

Geohash.encode 47.6062095, -122.3320708, 6
#=> "c23nb6"

Decode from geohash

Geohash.decode 'c23nb6'
#=> [[47.603759765625, -122.332763671875], [47.6092529296875, -122.32177734375]]

Adjacent

Geohash.adjacent 'c23nb6', :top
#=> "c23nb7"

Neighbors

Geohash.neighbors 'xn774c'
#=> ["xn774f", "xn7754", "xn7751", "xn7750", "xn774b", "xn7748", "xn7749", "xn774d"]

=begin
+--------+--------+--------+
| xn774d | xn774f | xn7754 |
+--------+--------+--------+
| xn7749 | xn774c | xn7751 |
+--------+--------+--------+
| xn7748 | xn774b | xn7750 |
+--------+--------+--------+
=end

Walk

Geohash.walk 'xn774c', [
  :top,
  :right,
  :bottom, :bottom,
  :left, :left,
  :top, :top
]
#=> ["xn774f", "xn7754", "xn7751", "xn7750", "xn774b", "xn7748", "xn7749", "xn774d"]
# implementation of `neighbors`

License

This project is copyright by Creasty, released under the MIT lisence.
See LICENSE file for details.

About

Geohash en/decode library written in ruby

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages