An Adaptive Algorithm for Geofencing