  Dark sirens, i.e., gravitational-wave (GW) sources without electromagnetic
counterparts, are new probes of the expansion of the universe. The efficacy of
this method relies on correctly localizing the host galaxies. However, recent
theoretical studies have shown that astrophysical environments could mislead
the spatial localization by distorting the GW signals. It is unclear whether
and to what degree the incorrect spatial localizations of dark sirens would
impair the accuracy of the measurement of the cosmological parameters. To
address this issue, we consider the future observations of dark sirens using
the Cosmic Explorer and the Einstein Telescope, and we design a Bayesian
framework to access the precision of measuring the Hubble-Lema\^itre constant
$H_0$. Interestingly, we find that the precision is not compromised when the
number of well-localized dark sirens is significantly below $300$, even in the
extreme scenario that all the dark sirens are localized incorrectly. As the
number exceeds $300$, the incorrect spatial localizations start to produce
statistically noticeable effects, such as a slow convergence of the posterior
distribution of $H_0$. We propose several tests that can be used in future
observations to verify the spatial localizations of dark sirens. Simulations of
these tests suggest that incorrect spatial localizations will dominate a
systematic error of $H_0$ if as much as $10\%$ of a sample of $300$
well-localized dark sirens are affected by their environments. Our results have
important implications for the long-term goal of measuring $H_0$ to a precision
of $<1\%$ using dark sirens.
