Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
masuidrive committed Oct 19, 2009
1 parent 4f02e33 commit aa758cb
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/pr_geohash.rb
Expand Up @@ -14,6 +14,11 @@
module GeoHash
VERSION = "1.0.0"

#########
# Decode from geohash
#
# geohash:: geohash code
# return:: decoded bounding box [[north latitude, west longitude],[south latitude, east longitude]]
def decode(geohash)
latlng = [[-90.0, 90.0], [-180.0, 180.0]]
is_lng = 1
Expand All @@ -27,6 +32,8 @@ def decode(geohash)
end
module_function :decode

#########
# Encode latitude and longitude into geohash
def encode(latitude, longitude, precision=12)
latlng = [latitude, longitude]
points = [[-90.0, 90.0], [-180.0, 180.0]]
Expand All @@ -44,6 +51,8 @@ def encode(latitude, longitude, precision=12)
end
module_function :encode

#########
# Calculate neighbors (8 adjacents) geohash
def neighbors(geohash)
[[:top, :right], [:right, :bottom], [:bottom, :left], [:left, :top]].map{ |dirs|
point = adjacent(geohash, dirs[0])
Expand All @@ -52,6 +61,8 @@ def neighbors(geohash)
end
module_function :neighbors

#########
# Calculate adjacents geohash
def adjacent(geohash, dir)
base, lastChr = geohash[0..-2], geohash[-1,1]
type = (geohash.length % 2)==1 ? :odd : :even
Expand Down

0 comments on commit aa758cb

Please sign in to comment.