Context. Star-forming complexes are large structures exhibiting massive star-formation at different stages of evolution, from dense cores to well-developed H ii regions. They are very interesting for the study of the formation and evolution of stars. NGC 6334 and NGC 6357 are two active and relatively nearby star-forming complexes. From the extinction map and the sub-mm cold dust emission, and because they have similar velocities, these regions are most likely connected. However, located in the direction of the Galactic center their radial velocity is not representative of their distance. An alternative is then to determine the distance of NGC 6334 and NGC 6357 from their stellar content. Aims. Our aim is to perform a census of O-B3 ionising stars in NGC 6334 and NGC 6357, to determine the extinction coefficient, and the distance of both regions. A census of O-B3 stars is an essential basis for estimating the statistical lifetime of the earliest massive star-forming phases. Methods. We performed a U, B, V, and R photometric survey of a large area covering NGC 6334 and NGC 6357 with the VIMOS (ESO-VLT) and the MOSAIC (CTIO) instruments. This allows us to have a complete census of O to B3 stars up to V = 22.6 mag. The OB stars are selected based on their U − B and B − V colors. The most robust extinction coefficient is determined from color−color plots before computing the distance of the OB stars. Results. We find a higher value than typical of the diffuse interstellar medium for R V of 3.53 ± 0.08 and 3.56 ± 0.15 for NGC 6357 and NGC 6334, respectively. Adopting these R V values, the distances of NGC 6357 and NGC 6334 are 1.9 ± 0.4 kpc and 1.7 ± 0.3 kpc. We conclude that, within the error bars, both regions are thus at the same distance of 1.75 kpc (weighted mean). We confirm that the value of R V is linked to the large dust grain content. In particular, we found that there are more very small grains in NGC 6357 than in NGC 6334, suggesting that NGC 6357 could be more evolved than NGC 6334. Placed in the Galactic context, the NGC 6334-NGC 6357 complex appears to be located at the inner edge of the Sagittarius-Carina arm. Our census of O to B3 stars leads to a count of ∼230, which allows us to determine the statistical lifetime of the earliest phases of the massive stars. The starless and the protostellar phases have a mean statistical lifetime of ∼1.5 × 10 4 yr and ∼2.2 × 10 5 yr, respectively.