I'm sure this comes up all the time and I've done some searching on it but there are so many methods and theories out there that I'm a little confused at this point.
I have a database of all(most) of the zip codes, latitudes, longitudes and pertinent information. I'm trying to query this database and return the zip code results within a radius of the input zip. I have the information of my input zip and I'm trying to run it but I keep returning an empty result set. This is the formula that I found online that other people have had success with but I can't seem to get it working. Does anyone have any suggestions? Am I way off base here?
As always, thanks in advance!!
Formula 1 - No errors, empty result set
SELECT distinct(zip) FROM Build00GeoData WHERE ( POWER(latitude - 41.77, 2) + POWER(longitude - 71.35, 2) ) < POWER(10,2)
Formula 2 - No erros, empty result set
/*I'm using php here but for MySQL purposes, I did remove the variables and PHP syntax then replaced with hard numbers*/ SELECT distinct(zip) FROM Build00GeoData WHERE (3958*3.1415926*sqrt((Latitude-'.$lat.')*(Latitude-'.$lat.') + cos(Latitude/57.29578)*cos('.$lat.'/57.29578)*(Longitude-'.$lon.')*(Longitude-'.$lon.'))/180) <= '.$radius.
This post has been edited by guyfromri: 19 May 2014 - 01:19 PM