ST_GeoHash

TL;DR

ST_GeoHash encodes a point location as a GeoHash string of the requested maximum length.

Syntax

ST_GeoHash(geom, max_length)
ST_GeoHash(longitude, latitude, max_length)

Arguments

geom is a GEOMETRY point. longitude and latitude are FLOAT64 coordinates. max_length is an INT64 GeoHash length.

Return Value

Returns a VARCHAR GeoHash.

Usage Notes

The geometry overload and the longitude/latitude overload encode the same location in the same coordinate order: longitude first, latitude second.

Examples

DROP DATABASE IF EXISTS geo_st_geohash_demo;
CREATE DATABASE geo_st_geohash_demo;
USE geo_st_geohash_demo;

SELECT ST_GeoHash(ST_GeomFromText('POINT(-5.603 42.605)'), 5) AS from_point;
SELECT ST_GeoHash(-5.603, 42.605, 5) AS from_coordinates;
SELECT ST_GeoHash(0, 0, 11) AS origin_hash;

DROP DATABASE geo_st_geohash_demo;

See Also

ST_LatFromGeoHash, ST_LongFromGeoHash, ST_PointFromGeoHash