We study the task allocation problem: how a set of mobile agents can best monitor a convex region and at the same time localize events such as biochemical threats that appear in the region. As the agents move towards an event to localize it, the coverage of the region deteriorates; on the other hand, if an agent does not help in localizing an event, it will take longer for other agents to localize it. The decision on how an agent should trade off localization and coverage depends on a particular network deployment. We show how different deployments can be parametrized and propose a distributed algorithm to solve the task allocation problem. The algorithm is shown to be stable and scalable, and is shown to converge to an optimal equilibrium position. The proposed parametrization of the task allocation problem depends on the number of agents in the network; we thus present a fast and robust algorithm based on consensus protocols for estimating this number.