Skip to content

Instantly share code, notes, and snippets.

@godrix
Last active September 25, 2019 14:03
Show Gist options
  • Save godrix/f54b104e5a13bcd8f0bd731352f192ad to your computer and use it in GitHub Desktop.
Save godrix/f54b104e5a13bcd8f0bd731352f192ad to your computer and use it in GitHub Desktop.
Método Haversine
SELECT *, (6371 *
acos(
cos(radians({{GEO.LAT}})) *
cos(radians(lat)) *
cos(radians({{GEO.LONG}}) - radians(lng)) +
sin(radians({{GEO.LAT}})) *
sin(radians(lat))
)) AS distance
FROM tabela LOCATION distance <= {{RANGE.KM}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment