Calculates the distance between two points in units (default is kilometers).
geoDistance(point1, point2[, units])
|point1||Required. GeoJSON Point specifying the origin.|
|point2||Required. GeoJSON Point specifying the destination.|
|units||Optional. Specified as a string. Options are ‘degrees’, ‘radians’, ‘miles’, or ‘kilometers’. Default is ‘kilometers’.|
Calculate the distance, in miles, between HarperDB’s headquarters and the Washington Monument.
SELECT geoDistance([-104.979127,39.761563], [-77.035248,38.889475], 'miles')
Find all locations that are within 40 kilometers of a given point, return that distance in miles, and sort by distance in an ascending order.
SELECT *, geoDistance([-104.979127,39.761563], geo_data, 'miles') as distance FROM dev.locations WHERE geoDistance([-104.979127,39.761563], geo_data, 'kilometers') < 40 ORDER BY distance ASC