search - what's the efficient algorithm to find points in a circle based on geographic coordinates? -
i'm working on implementation finding nearest person based on geographic coordinates. example, person a has coordinates(longitude , latitude ) m, , want find person within circle of center m radius x.
i plan store geographic coordinates in mysql database, what's efficient way search nearest coordinates?
my specific question is:
- what fields should stored in database efficient search? plan store persons' coordinates only.
- what's algorithm finding nearest person? plan calculate distance between person a's coordinate , coordinates stores in database.
however, think less efficient calculate if number of coordinates huge in database.
what's better way achieve application?
a simple pithagoras theorem application:
-- coordinates of person @ center of "circle" set @x0 = (select x persons id=1), @y0 = (select y persons id=1); -- calculate distance each point in persons table, excluding "center" select *, sqrt(pow(x - @x0, 2) + pow(y - @y0, 2)) distance persons id != 1 order sqrt(pow(x - @x0, 2) + pow(y - @y0, 2))
Comments
Post a Comment