Optical dimensional measurements have to be corrected for the refractive index of air. The refractive index is conventionally calculated from parameters of ambient air using either Edlén or Ciddor equations or their modified versions. However, these equations require an accurate knowledge of ambient conditions and especially the temperature of air. For example, to reach an uncertainty of 10−7 in dimensions, the air temperature has to be known at ~100 mK level. This does not necessarily cause problems in a stable laboratory environment. However, if measurements are done outdoors or in an industrial environment, variations in temperature can be very rapid and local temperature gradients can cause significant error if not taken into account. Moreover, if the required distance is long, the temperature over the whole measurement path can be impractical or impossible to determine at sufficient temporal or spatial resolution by conventional temperature measurement techniques. The developed method based on molecular spectroscopy of oxygen allows both lateral spatial and temporal overlap of the temperature measurement with the actual distance measurement. Temperature measurement using spectroscopy is based on a line intensity ratio measurement of two oxygen absorption lines, previously applied for measurements of high temperatures in flames. The oxygen absorption band at 762 nm is a convenient choice for two-line thermometry since the line strengths are practical for short- and long-distance measurements and suitable distributed feedback lasers are commercially available. Measurements done on a 67 m path at ambient conditions demonstrate that the RMS noise of 22mK, or 7.5 × 10−5, near 293 K using 60 s measurement time can be achieved, which is to our knowledge the best reported resolution.