Using housing market data of Beijing and Hangzhou, China, we conduct a case study to detect how the difference of urban structure can affect the relationship between the subway system and housing prices. To quantify the characteristics of urban structure, we propose a constrained clustering method, which can not only reveal the spatial heterogeneity of the housing market, but also provides a link between heterogeneity and the underlying urban structure. Applying constrained clustering to Beijing and Hangzhou, we find that the relationship between accessibility to metro stations and housing prices is weak and vulnerable, while the improvement of commuting efficiency, measured by a key variable, the metro index, does have a robust connection to metro premium on housing units. In particular, only a large metro index can be associated with a positive metro premium. Structural features, such as the size of urban core and the existence of multiple sub-centers, influence the metro premium by affecting the value and spatial distribution of the metro index. The evidence from Beijing and Hangzhou supports that in a mono-centric city, the size of the urban core is positively associated with the metro index and the metro premium, while in a poly-centric city with a small urban core, the metro index tends to be lower in the core region and higher in the satellite regions, which enforces the metro premium to be negative in the core while positive outside of the core.