Fastest distance lookup given latitude/longitude?
Posted
by Ryan Detzel
on Stack Overflow
See other posts from Stack Overflow
or by Ryan Detzel
Published on 2009-06-17T12:22:41Z
Indexed on
2010/03/20
11:21 UTC
Read the original article
Hit count: 586
I currently have just under a million locations in a mysql database all with longitude and latitude information. With this I use another lat/lng to find the distance of certain places in the database but it's not as fast as I want it to be especially with 100+ hits a second. Is there a faster formula or possibly a faster system other than mysql for this? The formula I'm using is this.
select name, ( 3959 * acos( cos( radians(42.290763) ) * cos( radians( locations.lat ) ) * cos( radians( locations.lng ) - radians(-71.35368) ) + sin( radians(42.290763) ) * sin( radians( locations.lat ) ) ) ) AS distance from locations where active = 1 HAVING distance < 10 ORDER BY distance;
© Stack Overflow or respective owner