Re: A "How would you do this"-type of question. not Java-specific.
korto.wow@gmail.com wrote:
Imagine you are writing a program that will display a map of the United
States. Your program will ask a user to input their ZIP code. Once
they do, a dot will appear on the map to indicate where that ZIP code
is located.
My question is, how would you go about doing something like this?
Would you have a file of all ZIP codes and their longitude, latitude
coords and extrapolate those to x,y coords on your graphic map? Or, is
there an easier way?
I can't think of a better approach. The assignment of
ZIP codes (USA postal codes) to geographical location is an
arbitrary encoding -- some large-scale patterns are evident
but they're not regular enough that you could derive map
coordinates from numerical calculations on the codes.[*]
May as well treat them as arbitrary keys and look them up
in a table.
Extrapolation doesn't seem to enter the picture, though.
[*] Mathematically, of course, one could always build a
polynomial of degree 100000 or less that interpolates every
five-digit ZIP code to its latitude, and another polynomial
for longitude. You might, however, have some difficulty in
evaluating such high-degree polynomials with useful accuracy!
In fact, I rather suspect that simply storing the coefficients
(as pairs of BigIntegers representing rational numbers, say)
might take more memory than the average 32-bit JVM can supply.
--
Eric Sosman
esosman@acm-dot-org.invalid