Many complex systems are organized in the form of a network embedded in space. Important examples include the physical Internet infrastructure, road networks, flight connections, brain functional networks, and social networks. The effect of space on network topology has recently come under the spotlight because of the emergence of pervasive technologies based on geolocalization, which constantly fill databases with people's movements and thus reveal their trajectories and spatial behavior. Extracting patterns and regularities from the resulting massive amount of human mobility data requires the development of appropriate tools for uncovering information in spatially embedded networks. In contrast with most works that tend to apply standard network metrics to any type of network, we argue in this paper for a careful treatment of the constraints imposed by space on network topology. In particular, we focus on the problem of community detection and propose a modularity function adapted to spatial networks. We show that it is possible to factor out the effect of space in order to reveal more clearly hidden structural similarities between the nodes. Methods are tested on a large mobile phone network and computer-generated benchmarks where the effect of space has been incorporated.