I have an application that pulls data from the database and adds it to the map, but I wanted you to only display places that are 20km from my current location, how do I do that using geolocation?
I have an application that pulls data from the database and adds it to the map, but I wanted you to only display places that are 20km from my current location, how do I do that using geolocation?
<?php
$latitude = -XX.YYYY; //Coloque sua latitude
$longitude = -XX.YYYY;//Coloque sua longitude
$km = 20;//Distância
$query = "
SELECT 'cep', (6371 * acos(cos(radians($latitude)) *
cos(radians('latitude')) *
cos(radians('longitude') - radians($longitude)) +
sin(radians($latitude)) *
sin(radians('latitude'))))
AS 'distancia'
FROM 'tb_enderecos'
HAVING 'distancia' < $km
ORDER BY 'distancia' ASC
LIMIT 10;"; //Limita registros
?>