Java Reference
In-Depth Information
76
}
77
}
78
79
// Returns spherical distance in miles given the latitude
80
// and longitude of two points (depends on constant RADIUS)
81
public static double distance( double lat1, double long1,
82
double lat2, double long2) {
83
lat1 = Math.toRadians(lat1);
84
long1 = Math.toRadians(long1);
85
lat2 = Math.toRadians(lat2);
86
long2 = Math.toRadians(long2);
87
double theCos = Math.sin(lat1) * Math.sin(lat2) +
88
Math.cos(lat1) * Math.cos(lat2) * Math.cos(long1 - long2);
89
double arcLength = Math.acos(theCos);
90
return arcLength * RADIUS;
91
}
92 }
Here is a sample execution:
Welcome to the zip code database.
Give me a 5-digit zip code and a
proximity, and I'll tell you where
that zip code is located, along
with a list of other zip codes
within the given proximity.
What zip code are you interested in? 98104
And what proximity (in miles)? 1
98104: Seattle, WA
zip codes within 1.0 miles:
98101 Seattle, WA, 0.62 miles
98104 Seattle, WA, 0.00 miles
98154 Seattle, WA, 0.35 miles
98164 Seattle, WA, 0.29 miles
98174 Seattle, WA, 0.35 miles
There is an old saying that you get what you pay for, and these zip code data are
no exception. There are several web sites that list zip codes within a mile of 98104,
and they include many zip codes not included here. That's because the free zip code
information is incomplete. Each of those web sites gives you the option of obtaining
a better database for a small fee.
 
Search WWH ::




Custom Search