What is the best way to efficiently calculate which points are close to a given lat/long using MySQL?

Try reading this article: Creating a Store Locator with PHP, MySQL & Google Maps That article shows a MySQL solution for the Haversine formula which is the best way to compute distance given latitude and longitude.

Up vote 8 down vote favorite 3 share g+ share fb share tw.

I'm trying to design a MySQL schema that can store a list of users with an associated latitude and longitude. I would then, for a given user, like to build a query which can return the nearest 50 users to him/her and sort those users by distance (with the nearest being presented first). Given that there may be many thousands of users in this table, what is the most efficient way to store and query this data?

Mysql geospatial computational-geometry link|improve this question asked Jun 30 '10 at 23:15Andrew J1516 83% accept rate.

It natively supports spatial data types, and has a bunch of comparision operators for proximity, enclosure, etc... – HorusKol Jun 30 '10 at 23:33 MongoDB supports out-of-the-box Geospatial Index; the core use case is same one you have summarized (e.g. , your exemplary queries are nearly identical to the ones in the Mongo summary page on G/I. – doug Nov 14 '11 at 10:52.

Try reading this article: Creating a Store Locator with PHP, MySQL & Google Maps That article shows a MySQL solution for the Haversine formula, which is the best way to compute distance given latitude and longitude.

You've been answering all the same posts as me today.... – Abe Miessler Jun 30 '10 at 23:31 Nope, it's just that great minds think alike! :) – Bill Karwin Jun 30 '10 at 23:46.

Take a look at MySql's spatial indexing. You can also use the Great Circle Distance, there is a good SO article on it here.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions