mysql - Finding Cities within 'X' Kilometers (or Miles) -


this may or may not clear, leave me comment if off base, or need more information. perhaps there solution out there want in php.

i looking function add or subtract distance longitude or latitude value.

reason: have database latitudes , longitudes in , want form query extract cities within x kilometers (or miles). query this...

select * cities (longitude > x1 , longitude < x2) , (latitude > y1 , latitude < y2)   x1 = longitude - (distance)  x2 = longitude + (distance)   y1 = latitude - (distance)  y2 = latitude + (distance) 

i working in php, mysql database.

open suggestions also! :)

this mysql query want. keep in mind things approximations generally, earth not spherical nor take account mountains, hills, valleys, etc.. use code on academichomes.com php , mysql, returns records within $radius miles of $latitude, $longitude.

$res = mysql_query("select     *      your_table     (         (69.1 * (latitude - " . $latitude . ")) *          (69.1 * (latitude - " . $latitude . "))     ) + (          (69.1 * (longitude - " . $longitude . ") * cos(" . $latitude . " / 57.3)) *          (69.1 * (longitude - " . $longitude . ") * cos(" . $latitude . " / 57.3))     ) < " . pow($radius, 2) . "  order      (         (69.1 * (latitude - " . $latitude . ")) *          (69.1 * (latitude - " . $latitude . "))     ) + (          (69.1 * (longitude - " . $longitude . ") * cos(" . $latitude . " / 57.3)) *          (69.1 * (longitude - " . $longitude . ") * cos(" . $latitude . " / 57.3))     ) asc"); 

Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -