Skip to content

Instantly share code, notes, and snippets.

@RanKey1496
Created March 8, 2018 16:20
Show Gist options
  • Save RanKey1496/1df26d0444ea4ad1426abff592874801 to your computer and use it in GitHub Desktop.
Save RanKey1496/1df26d0444ea4ad1426abff592874801 to your computer and use it in GitHub Desktop.
Geospatial query that search properties nearby to a point
SELECT
prom.id, p.id, p.direccion, p.latitud, p.longitud,
(
6371 *
ACOS(
COS( RADIANS( 6.250020 ) ) *
COS( RADIANS( `latitud` ) ) *
COS(
RADIANS( `longitud` ) - RADIANS( -75.568510 )
) +
SIN(RADIANS( 6.250020 )) *
SIN(RADIANS(`latitud`))
)
) `distance`
FROM
Propiedad p
INNER JOIN Promocion prom ON p.id = prom.id_propiedad
HAVING
`distance` < 1
ORDER BY
`distance` ASC
LIMIT 10 OFFSET 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment