Also some zip codes are huge, so the results are pretty meaningless in those areas.
That is why the systems that calculate distance based on the street address are much better. In any case, if you have the longitude and latitude of two zipcodes you can calculate the distance in this way. This only works for north America. SET VAR vLat1 DOUBLE = 35 --north SET VAR vLat2 DOUBLE = 36 --north SET VAR vLong1 DOUBLE = 35 --west SET VAR vLong2 DOUBLE = 36 --west SET VAR vD DOUBLE SET VAR vDistance DOUBLE = 0 SET VAR vCosD DOUBLE SET VAR vLong1 = (0-(.vLong1 * .#PI / 180)) SET VAR vLong2 = (0-(.vLong2 * .#PI / 180)) SET VAR vLat1 = (.vLat1 * .#PI / 180) SET VAR vLat2 = (.vLat2 * .#PI / 180) SET VAR vCosD = (COS(.vLat1) * COS(.vLong1) * COS(.vLat2) * COS(.vLong2)) SET VAR vCosD = (.vCosD + (COS(.vLat1) * SIN(.vLong1) * COS(.vLat2) * SIN(.vLong2))) SET VAR vCosD = (.vCosD + (SIN(.vLat1) * SIN(.vLat2))) SET VAR vD = (ACOS(.vCosD)) SET VAR vDMiles = (3959 * .vD) SET VAR vDistance = ((INT((.vDMiles * 100) + 0.5)) / 100) Dennis McGrath -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Javier Valencia Sent: Tuesday, August 11, 2009 3:23 PM To: RBASE-L Mailing List Subject: [RBASE-L] - RE: SOT: zip codes Dan, This is a piece of cake if you have GIS available. In your case, you can download files with the centroid for each zip code from sites, such as this: http://www.census.gov/geo/www/tiger/zip1999.zip It comes as a Word Document and a DBF database. I believe the Post Office also has files you can download at no cost. You can simplify the calculation dramatically if you ignore earth's curvature and assume a straight line between centroids. Since you are not looking at large distances the difference should not be too bad. I am sure that you can download freeware calculators that would do the calculations including all factors. One item that you need to consider is whether you want a straight line distance or a driving distance; the difference between these two approaches could be large. You can also create an expression and pass it on to Google (if Internet is available) and let Google (or any mapping service) do the work for you. Javier, Javier Valencia 913-915-3137 -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Dan Goldberg Sent: Tuesday, August 11, 2009 1:06 PM To: RBASE-L Mailing List Subject: [RBASE-L] - SOT: zip codes I am investigating on how to find the nearest zip code from another zip code based on distance. I am working on a dealer locator solution. I was wondering if anybody else has done this in Rbase. I am thinking there is an additional data field needed to determine the physical location(maybe latitude and longitude??). I am not sure. I know there are hosted solutions but I am looking for an in house solution to save some $$$. TIA Dan Goldberg

