View Source Geohax (geohax v1.0.2)

Geohash encoding and decoding.

Summary

Functions

Decodes a Geohash to a position {longitude, latitude}.

Encodes a position longitude, latitude to a Geohash of precision length.

Finds neighbor of a Geohash in a given direction.

Finds neighbors of a Geohash.

Finds all the Geohashes within {min_lon, min_lat}, {max_lon, max_lat} with the given precision.

Types

@type direction() :: :north | :south | :east | :west
@type latitude() :: float()
@type longitude() :: float()

Functions

@spec decode(String.t()) :: {longitude(), latitude()}

Decodes a Geohash to a position {longitude, latitude}.

Example

iex> Geohax.decode("311x1r")
{-132.83, -38.1033}
Link to this function

encode(longitude, latitude, precision \\ 12)

View Source
@spec encode(longitude(), latitude(), pos_integer()) :: String.t()

Encodes a position longitude, latitude to a Geohash of precision length.

Example

iex> Geohax.encode(-132.83, -38.1033, 6)
"311x1r"
Link to this function

neighbor(geohash, direction)

View Source
@spec neighbor(String.t(), direction()) :: String.t()

Finds neighbor of a Geohash in a given direction.

Allowed directions are :north, :south, :east and :west.

Example

iex> Geohax.neighbor("311x1r", :north)
"311x32"
@spec neighbors(String.t()) :: %{required(direction()) => String.t()}

Finds neighbors of a Geohash.

Example

iex> Geohax.neighbors("311x1r")
%{north: "311x32", south: "311x1q", east: "311x1x", west: "311x1p"}
Link to this function

within(arg1, arg2, precision \\ 5)

View Source
@spec within({longitude(), latitude()}, {longitude(), latitude()}, pos_integer()) :: [
  String.t()
]

Finds all the Geohashes within {min_lon, min_lat}, {max_lon, max_lat} with the given precision.

Examples

iex> Geohax.within({16.731831, 52.291725}, {17.071703, 52.508736})
["u37ck", "u37cm", "u37cq", "u37cr", "u3k12", "u3k13", "u3k16", "u3k17",
 "u3k1k", "u37cs", "u37ct", "u37cw", "u37cx", "u3k18", "u3k19", "u3k1d",
 "u3k1e", "u3k1s", "u37cu", "u37cv", "u37cy", "u37cz", "u3k1b", "u3k1c",
 "u3k1f", "u3k1g", "u3k1u", "u37fh", "u37fj", "u37fn", "u37fp", "u3k40",
 "u3k41", "u3k44", "u3k45", "u3k4h", "u37fk", "u37fm", "u37fq", "u37fr",
 "u3k42", "u3k43", "u3k46", "u3k47", "u3k4k", "u37fs", "u37ft", "u37fw",
 "u37fx", "u3k48", "u3k49", "u3k4d", "u3k4e", "u3k4s"]

iex> Geohax.within({16.731831, 52.291725}, {17.071703, 52.508736}, 3)
["u37", "u3k"]