All Products
Search
Document Center

PolarDB:ST_H3FromLatLng

Last Updated:Mar 28, 2026

Converts a latitude and longitude coordinate pair to an H3Grid object at the specified resolution level.

Syntax

h3grid ST_H3FromLatLng(float lat, float lng, Integer level)

Parameters

ParameterTypeDescription
latfloatThe latitude of the coordinate.
lngfloatThe longitude of the coordinate.
levelIntegerThe H3 resolution level. Default value: 15.

Examples

The following examples convert the coordinate (20.5, 128.2) to an H3Grid object and return its text representation using ST_AsText.

Example 1: Use the default resolution level (15)

SELECT ST_AsText(ST_H3FromLatLng(20.5, 128.2));

Output:

    st_astext
-----------------
 8f4a1266884c4f0

Example 2: Specify a resolution level

SELECT ST_AsText(ST_H3FromLatLng(20.5, 128.2, 8));

Output:

    st_astext
-----------------
 884a126689fffff

A lower resolution level produces a larger, coarser grid cell. In Example 2, level 8 returns the cell 884a126689fffff, which covers a broader area than the level-15 cell returned in Example 1.