Added an optional maximum distance to limit the stores.