Categories:

Geospatial functions

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 degrees.

Note

Snowflake recommends using the ST_DISTANCE function instead.

Syntax¶

HAVERSINE( lat1, lon1, lat2, lon2 )
Copy

Examples¶

The following example returns the geospatial distance in kilometers between New York and Los Angeles:

SELECT HAVERSINE(40.7127, -74.0059, 34.0500, -118.2500);
+--------------------------------------------------+
| HAVERSINE(40.7127, -74.0059, 34.0500, -118.2500) |
|--------------------------------------------------|
|                                   3936.385096389 |
+--------------------------------------------------+
Copy