improved algorithm to detect longs/lats