Subject zip code distance calculation
Author irajoel2000
I use the following sql statement with dbase tables to return records
that are a certain distance from a zipcode. Each record has a latitude
and a longitude and a cosine. I then cycle through the rowset and
filter out those records that are <= the request milage, ie: 10 miles
from 10011.

I am trying to upgrade to firebird, but the sql statement seems not to
work with firebird. I'm thinking there must be some other proven way to
return the records that are a certain distance from a known lat and
long. Maybe a better sql statment or a store procedure. Id rather not
reinvent the wheel if this has already been fiqured out. Any idea
apprciated.


lat = 40.9999
lon = -77.876

"SELECT ((69.1*(:lat-LATITUDE))*(69.1*(:lat-LATITUDE))+(69.1*(:lon-
(LONGITUDE))*COSINE)*(69.1*(:lon-(LONGITUDE))*COSINE)) AS DISTANCE,
LATITUDE, LONGITUDE, COSINE, WEBTYPE, NAME, NOTE, IDNUM,
TYPE1,NAME2,CONTACT,ADDRESS1,ADDRESS2,CITY,STATE,ZIP,EDATE, PHONE, EXT,
HOTLINE, FAX, INTERNET, DESCRIPT, WWWEB, GIVE_ADDR, WEBSITE FROM
hotline WHERE WEBSITE = 'Y' AND CLOSED = 'N' ORDER BY WEBTYPE, NAME"

Thanks