Jerry,
I don't know if you are aware that there is a software package in the PostgreSQL contrib tree that might help you (or that do what you want already, not sure).
Description: Additional facilities for PostgreSQL
The PostgreSQL contrib package provides several additional features for
the PostgreSQL database. contrib often serves as a testbed for features
before they are adopted into PostgreSQL proper:
.
earthdistance - Operator for computing the distance (in miles)
between two points on the earth's surface
-Roberto