Location-Based Services (LBSs) are attracting nowadays a great interest, mainly due to the economic value they can provide. So, different applications are being developed for tracking, navigation, advertising, etc., but most of those applications are designed for specific scenarios and goals with implicit knowledge about the application context. However, currently it is a challenge to provide a common framework that allows to manage knowledge obtained from data sent by heterogeneous moving objects (textual data, multimedia data, sensor data, etc.). Moreover, the challenge is even greater considering situations where the system must adapt itself to contexts where the knowledge changes dynamically and in which moving objects can use different underlying wireless technologies and positioning systems. In this paper we present the system SHERLOCK, that offers a common framework with new functionalities for LBSs. Our system processes user requests continuously to provide up-to-date answers in heterogeneous and dynamic contexts. Ontologies and semantic techniques are used to share knowledge among devices, which enables the system to guide the user selecting the service that best fits his/her needs in the given context. Moreover, the system uses mobile agent technology to carry the processing tasks wherever necessary in the dynamic underlying networks at any time.