Global

Members

(constant) BASE32 :string

BASE32

Type:
  • string
Source:

(constant) BASE32_DICT :object

BASE32_DICT

Type:
  • object
Source:

(constant) BORDER_CODEX :object

BORDER_CODEX

Type:
  • object
Source:

(constant) ENCODE_AUTO :number

ENCODE_AUTO

Type:
  • number
Source:

(constant) MAX_LAT :number

MAX_LAT Maximum latitude 90º north of the equator

Type:
  • number
Source:

(constant) MAX_LNG :number

Maximum longitude 180º east of the prime meridian

Type:
  • number
Source:

(constant) MIN_LAT :number

Minimum latitude 90º south (-90º) of the equator

Type:
  • number
Source:

(constant) MIN_LNG :number

Minimum longitude 180º west (-180º) of the prime meridian

Type:
  • number
Source:

(constant) NEIGHBOR_CODEX :object

NEIGHBOR_CODEX

Type:
  • object
Source:

(constant) PRECISION_AREA :object

PRECISION_AREA

Type:
  • object
Source:

(constant) SIGFIG_HASH_LENGTH :Array

Significant Figure Hash Length

This is a quick and dirty lookup to figure out how long our hash should be in order to guarantee a certain amount of trailing significant figures. This was calculated by determining the error: 45/2^(n-1) where n is the number of bits for a latitude or longitude. Key is number of desired sig figs, value is minimum length of the geohash.

Type:
  • Array
Source:

Methods

clamp(n, min, max) → {number|*}

basic number clamp

Parameters:
Name Type Description
n number

number to clamp

min number

minimum value

max number

maximum value

Source:
Returns:
  • clamped value
Type
number | *

clampRelative(n, min, max) → {number|*}

basic relative value clamp

Parameters:
Name Type Description
n number

number to clamp

min number

minimum value

max number

maximum value

Source:
Returns:
  • clamped value or offset
Type
number | *

decode(geohash, calculateErrorOffsetopt) → {Object|Object}

decode Decode geohash to latitude/longitude (location is approximate centre of geohash cell, to reasonable precision). Will round to close to centre without excessive precision: ⌊2-log10(Δ°)⌋ decimal places.

Parameters:
Name Type Attributes Default Description
geohash string

Geohash string to be converted to latitude/longitude.

calculateErrorOffset boolean <optional>
false

calculate the natural amount of geospatial inaccuracy

Source:
Throws:

Invalid geohash.

Returns:
  • Center of geohashed location.
Type
Object | Object
Example
const latlng = decode( 'dqbvhgk' ); // latlng: { lng: -77.4804, lat: 38.8662 }

determinePrecision(lng, lat, precisionopt, nullable) → {number}

Estimate what precision to use based on the input longitude/latitude

Parameters:
Name Type Attributes Default Description
lng number

longitude

lat number

latitude

precision number <optional>
<nullable>
ENCODE_AUTO

precision override

Source:
Returns:
  • precision estimate
Type
number

encode(lng, lat, precisionopt) → {string}

encode Encodes latitude/longitude to geohash, either to specified precision or to automatically evaluated precision.

Parameters:
Name Type Attributes Default Description
lng number

Longitude in degrees.

lat number

Latitude in degrees.

precision number <optional>
ENCODE_AUTO

Number of characters in resulting geohash.

Source:
Throws:

Invalid geohash.

Returns:

Geohash of supplied latitude/longitude.

Type
string
Example
const geohash = Geohash.encode(52.205, 0.119, 7); // geohash: 'u120fxw'

geohashesWithinBBox(minLng, minLat, maxLng, maxLat, precisionopt) → {Array}

geohashesWithinBBox

Return all the geohashes between minLng, minLat, maxLng, maxLat at the specified precision

Parameters:
Name Type Attributes Default Description
minLng number

bbox min longitude

minLat number

bbox min latitude

maxLng number

bbox max longitude

maxLat number

bbox max latitude

precision number <optional>
ENCODE_AUTO

geohash precision

Source:
Returns:
  • geohash array
Type
Array

geohashesWithinBBoxToGeoJSON(minLng, minLat, maxLng, maxLat, precisionopt) → {Object}

geohashesWithinBBoxToGeoJSON

Return GeoJSON FeatureCollection of all geohashes between minLng, minLat, maxLng, maxLat at the specified precision

Parameters:
Name Type Attributes Default Description
minLng number

bbox min longitude

minLat number

bbox min latitude

maxLng number

bbox max longitude

maxLat number

bbox max latitude

precision number <optional>
ENCODE_AUTO

geohash precision

Source:
Returns:

GeoJSON of geohashes within a bbox

Type
Object

geohashToBBox(hash) → {Array.<number>}

Returns BBox bounds of specified geohash.

Parameters:
Name Type Description
hash string

geohash to convert to bbox

Source:
Throws:

Invalid geohash.

Returns:

bbox array

Type
Array.<number>

getBBoxStartingPoint(minLng, minLat, maxLng, maxLat, precisionopt) → {Object}

getBBoxStartingPoint

Beginning operations for generating a geohash bbox. Get the geohash for the southwest corner of a bbox and how many hash steps there are to the northeast corner.

Parameters:
Name Type Attributes Default Description
minLng number

minimum longitude

minLat number

minimum latitude

maxLng number

maximum longitude

maxLat number

maximum latitude

precision number <optional>
ENCODE_AUTO

geohash precision

Source:
Returns:

southwest hash and how many lng/lat steps to the northeast hash

Type
Object

isNumber(n) → {boolean}

determine if value is a valid number

Parameters:
Name Type Description
n number

value

Source:
Returns:
  • true if value is a number
Type
boolean

latitudeClamp(lat) → {number}

Determines if latitude is in the realm of possibility If it's not, clamp the latitude value to the MIN/MAX

Parameters:
Name Type Description
lat number

latitude

Source:
Returns:
  • latitude
Type
number

latitudeClampRelative(lat) → {number}

Determines if latitude is in the realm of possibility If it's not, return the latitude position relative to the amount offset

Parameters:
Name Type Description
lat number

latitude

Source:
Returns:
  • latitude
Type
number

longitudeClamp(lng) → {number}

Determines if longitude is in the realm of possibility If it's not, clamp the longitude value to the MIN/MAX

Parameters:
Name Type Description
lng number

longitude

Source:
Returns:
  • longitude
Type
number

longitudeClampRelative(lng) → {number}

Determines if longitude is in the realm of possibility If it's not, return the longitude position relative to the amount offset

Parameters:
Name Type Description
lng number

longitude

Source:
Returns:
  • longitude
Type
number

neighbor(geohash, direction) → {string}

Determines neighbor cell in given direction.

Parameters:
Name Type Description
geohash string

Cell to which neighbor cell is required.

direction string

Direction from geohash (N/S/E/W).

Source:
Throws:

Invalid geohash.

Returns:

Geocode of neighbor cell.

Type
string

neighbors(geohash, asObject) → {Object|array}

neighbors Returns all 8 neighbor cells to specified geohash. This algorithm is approximately two times faster than ngeohash. Times for 1,000,000 iterations | ngeohash | Geohash | | 0m3.108s | 0m1.675s |

Parameters:
Name Type Default Description
geohash string

Geohash neighbors are required of.

asObject boolean false

to return as an object or array

Source:
Throws:

Invalid geohash.

Returns:
  • surrounding geohashes
Type
Object | array

sizeOf(geohash) → {Object}

sizeOf Calculate the size of a given geohash

Precision Width Height
1 ≤ 5,000km × 5,000km
2 ≤ 1,250km × 625km
3 ≤ 156km × 156km
4 ≤ 39.1km × 19.5km
5 ≤ 4.89km × 4.89km
6 ≤ 1.22km × 0.61km
7 ≤ 153m × 153m
8 ≤ 38.2m × 19.1m
9 ≤ 4.77m × 4.77m
10 ≤ 1.19m × 0.596m
11 ≤ 149mm × 149mm
12 ≤ 37.2mm × 18.6mm
Parameters:
Name Type Description
geohash string

Geohash to determine precision size

Source:
Returns:
  • area, width, and high in meters
Type
Object
Example
sizeOf( 'dqcjpxetz' );
// { geohash: 'dqcjpxetz', precision: 9, width: 4.77, height: 4.77, area: 22.7527 }

toGeoJSON(hash, opts) → {*}

convert geohash to GeoJSON

Parameters:
Name Type Description
hash string

geohash to convert

opts object

geojson options

Properties
Name Type Attributes Default Description
includeGeohashAsProperty boolean <optional>
false

include geohash string as a property in the GeoJSON

includeFeatureBBox boolean <optional>
false

include bbox as a property in the GeoJSON

Source:
Returns:

geohash to geojson

Type
*

validGeohash(geohash) → {boolean}

validGeohash Determine if string is a valid geohash

Parameters:
Name Type Description
geohash string

geohash to test

Source:
Returns:
  • true/false if the geohash is valid
Type
boolean