We show how the distances to binary black holes measured in gravitational wave observations with ground-based interferometers can be used to constrain the redshift-distance relation and, thereby, measure the Hubble constant (H0). Gravitational wave observations of stellar-mass binary black holes are not expected to be accompanied by any electro-magnetic event that may help in accessing their redshifts. We address this deficiency by using an optical catalog to get the distribution of galaxies in redshift. Assuming that the clustering of the binaries is correlated with that of the galaxies, we propose using that correlation to measure H0. We show that employing this method on simulated data obtained for second-generation networks comprising at least three detectors, e.g., advanced LIGO -advanced VIRGO network, one can measure H0 with an accuracy of ∼ 8% with detection of a reference population of 25 binaries, each with black holes of mass 10M . As expected, with third-generation detectors like the Einstein telescope (ET), which will measure distances much more accurately and to greater depths, one can obtain better estimates for H0. Specifically, we show that with 25 observations, ET can constrain H0 to an accuracy of ∼7%. This method can also be used to estimate other cosmological parameters like the matter density Ωm and the dark energy equation of state.