JordanSmith1111 Posted September 28, 2013 Share Posted September 28, 2013 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 https://forums.phpfreaks.com/topic/282510-mysql-php-distance-results-lat-long-help/ Share on other sites More sharing options...
Barand Posted September 28, 2013 Share Posted September 28, 2013 After 20 seconds Googling http://stackoverflow.com/questions/6264571/calculate-distance-in-km-and-miles If you spend a little more time you might come up with something better Link to comment https://forums.phpfreaks.com/topic/282510-mysql-php-distance-results-lat-long-help/#findComment-1451603 Share on other sites More sharing options...
JordanSmith1111 Posted September 28, 2013 Author Share Posted September 28, 2013 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 Link to comment https://forums.phpfreaks.com/topic/282510-mysql-php-distance-results-lat-long-help/#findComment-1451604 Share on other sites More sharing options...
JordanSmith1111 Posted September 28, 2013 Author Share Posted September 28, 2013 nevermind, i got what you meant.. i had to find that formula and add it to whatever i had before. i just thought i had the entire deal but i didnt... now its all good. thanks for clearing the road ahead Link to comment https://forums.phpfreaks.com/topic/282510-mysql-php-distance-results-lat-long-help/#findComment-1451609 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.