This problem is a kind of closest pair between two disjoint set. Upperside picture
If you want to do binary search on spatial data, you could use a spatial data structure, such as a quadtree or a k-d tree.