Protection of users' privacy has been a central issue for location-based services (LBSs). In this paper, we classify two kinds of privacy protection requirements in LBS: location anonymity and identifier anonymity. While the location cloaking technique under the k-anonymity model can provide a good protection of users' privacy, it reduces the resolution of location information and, hence, may degrade the quality of service (QoS). To strike a balance between the location privacy and QoS, we present a quality-aware anonymity model for protecting location privacy while meeting user specified QoS requirements. In the model, a mobile user can specify the minimum anonymity level requirement upon location privacy as well as the maximum cloaking latency and the maximum cloaking region size requirements upon QoS. In accordance with the model, we develop an efficient directed-graph based cloaking algorithm to achieve both high-quality location anonymity and identifier anonymity. The performance objective is to maximize the cloaking success rate under the privacy and QoS constraints. Furthermore, we introduce an option of using dummy locations to achieve a 100% cloaking success rate at the cost of communication overhead. Experimental results show the effectiveness of our cloaking algorithm under various privacy and QoS requirements.