A relation between geometric phases and criticality of spin chains is established. As a result, we show how geometric phases can be exploited as a tool to detect regions of criticality without having to undergo a quantum phase transition. We analytically evaluate the geometric phase that corresponds to the ground and excited states of the anisotropic XY model in the presence of a transverse magnetic field when the direction of the anisotropy is adiabatically rotated. It is demonstrated that the resulting phase is resilient against the main sources of errors. A physical realization with ultracold atoms in optical lattices is presented.