Jump to content

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

Go to solution Solved by Barand,

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.