Understanding quantitative relationships between urban elements is crucial for a wide range of applications. The observation at the macroscopic level demonstrates that the aggregated urban quantities (e.g., gross domestic product) scale systematically with population sizes across cities, also known as urban scaling laws. However, at the mesoscopic level, we lack an understanding of whether the simple scaling relationship holds within cities, which is a fundamental question regarding the spatial origin of scaling in urban systems. Here, by analyzing four extensive datasets covering millions of mobile phone users and urban facilities, we investigate the scaling phenomena within cities. We find that the mesoscopic infrastructure volume and socioeconomic activity scale sub- and super-linearly with the active population, respectively. For a same scaling phenomenon, however, the exponents vary in cities of similar population sizes. To explain these empirical observations, we propose a conceptual framework by considering the heterogeneous distributions of population and facilities, and the spatial interactions between them. Analytical and numerical results suggest that, despite the large number of complexities that influence urban activities, the simple interaction rules can effectively explain the observed regularity and heterogeneity in scaling behaviors within cities.