Distance is a fundamental parameter in astronomical observations. How to accurately measure distances to objects has always been an important issue. Interstellar extinction, the absorption and scattering of starlight, affects the accuracy of distance measurements based on stellar physics. Therefore, an extinction correction is often required before distance measurements. For supernova remnants (SNRs) and molecular clouds (MCs), accurate estimates of their masses, physical sizes, and some other properties depend critically on accurate distance measurements. In this talk, I will introduce how we use the variation of extinction to measure the distances of a large set of SNRs and MCs. This method can further be applied to measure the distances to any dusty sources.