Well, I'm not sure exactly how it is implemented, but the MASON toolkit uses a discretization algorithm that places agents that are close to one another in the same "bucket" of a hash table. It makes for very fast lookups, as only a few of these buckets have to be checked for each query.
The best thing for you is probably to take a look at the source code here:
http://code.google.com/p/mason/source/browse/trunk/mason/sim/field/continuous/Continuous2D.java?r=529