Jump to content

MYSQL / PHP Distance results... Lat & Long.. help


JordanSmith1111

Recommended Posts

Hello guys

 

I came acrross with some information to display my database results given latitude and longitude values and sort it by distance

 

so far it works good but I was wondering how could i echo the actual distance between starting point and my results?

 

my database is pretty straight forward: id, username, lat (latitude), lng (longitude) and a couple more things that will not be used right now....

 

the sql request code:

$find = mysql_query("SELECT username, lat, lng, SQRT(
    POW(69.1 * (lat - '".$latitude."'), 2) +
    POW(69.1 * ('".$longitude."' - lng) * COS(lat / 57.3), 2)) AS distance
FROM users WHERE username != '".$usern."' HAVING distance >= 0 ORDER BY distance ASC");
while($row = mysql_fetch_array($find))
{
echo "<br />".$row['username'];
}

$latitude and $longitude is the current logged in member's location information

 

so, I would like to know how to echo the actual distance in miles???

 

so i could do something like :

echo $username."" is ".$distance." mile(s) from you...";

Thanks in advance!

i saw all those google scripts and this is the one that works the best for me, i just dont know how i can echo the actual distance. the script sorts the results from closer to farther but i want to be able to echo the miles between starting point and each result dropped

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.