most efficient way to find distances between many lat/lng using MySQL5.5

Hi all, after some current advise to best suit my requirements please.

I have a set of users with lat/lng in a table which although small at present I expect to grow into the hundreds of thousands over the next few years so I want to get this right to start with.

Normal scenario, for each one within a certain distance (say 5 miles) I want to return all the information such as name, age and distance from the searcher (who's lat/lng Ill have upon log in as a session)

My host uses MySQL5.5 so it appears I cannot use some of the newer built in MySQL distance features that I guess would help so I'm after the most efficient way to return and calculate please.

I've read about other types such as point etc and I can easily transform the lat/lngs to also be in a point column if that is better.

Please remember at present code must work on MySQL5.5

Thanks,
Neil

SELECT 
usr_id, 
usr_first_name, 
usr_location_lat, 
usr_location_lng, 
( 3959 * acos( cos( radians(51.33942032) ) * cos( radians( users.usr_location_lat ) ) * cos( radians(users.usr_location_lng) - radians(0.54173702)) + sin(radians(51.33942032)) * sin( radians(users.usr_location_lat)))) AS distance
FROM users 
ORDER BY 
usr_date_registered DESC 

Open in new window

LVL 3
Neil ThompsonSenior Systems DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin MillerCTOCommented:
Convert all floating point numbers AND calculations to integers; integer math is much faster to work with.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vijaya KumarCommented:
MYSQL 5.5 supports the distance functions such as cos,sin,acos.

visit this [https://dev.mysql.com/doc/refman/5.5/en/mathematical-functions.html]

Your code should be

SELECT 
usr_id, 
usr_first_name, 
usr_location_lat, 
usr_location_lng, 
( 3959 * acos( cos( radians(51.33942032) ) * cos( radians( users.usr_location_lat ) ) * cos( radians(users.usr_location_lng) - radians(0.54173702)) + sin(radians(51.33942032)) * sin( radians(users.usr_location_lat)))) AS distance
FROM users 
having distance <= 5
ORDER BY 
usr_date_registered DESC 

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.