php - Querying lat , long from db and show all records with in range -


i working on program stores latitude , longitude of users (using mysql , php).

i need make query , show list of users within 100 km range.

i stuck below issues

  1. db design faster result. db structure fine? if want faster output index on both lat , long work? should use innodb or myisam engines in below case. querying result in above said case take time if have hundreds of thousands of records

my sql table structure:

id(int 11 primary key auto increment) | lat(varchar) | long(varchar) 
  1. is there direct sql function or code in can users in specified range? googled , found of them using cos this. way?

query gives output, slow:

select id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) distance  markers  having distance < 25  order distance limit 0, 20; 

if use mysql >= 5.6.1, use function st_distance, see http://dev.mysql.com/doc/refman/5.6/en/spatial-relation-functions-object-shapes.html#function_st-distance

it requires use point type coordinates.


Comments