- Categories:
HAVERSINE¶
Calculates the great-circle distance in kilometers between two points on the Earth’s surface, using the Haversine formula. The two points are specified by their latitude and longitude in decimal degrees.
Note
Snowflake recommends using the ST_DISTANCE function instead of the HAVERSINE function. The ST_DISTANCE function performs the calculation using values of geospatial types, which enables you to store geospatial data and use the geospatial functions on the data. In addition, join predicates that use the ST_DISTANCE function perform better than join predicates that use the HAVERSINE function.
语法
实参
lat1第一个点的纬度,以十进制度为单位。
lon1第一个点的经度,以十进制度为单位。
lat2第二个点的纬度,以十进制度为单位。
lon2第二个点的经度,以十进制度为单位。
返回
此函数返回 FLOAT 类型的值。
示例
以下示例返回纽约和洛杉矶之间的地理空间距离(以千米为单位):
以下示例与前一示例相同,但通过将结果乘以 1000 返回地理空间距离,以米为单位而非千米: