1. A method of generating geofences, comprising: obtaining, by a mobile device, a current location of the mobile device; determining a plurality of nearest locations, the plurality of nearest locations being locations nearest to the current location of the mobile device out of a plurality of stored locations, wherein the mobile device can generate respective local geofences for the plurality of nearest locations; determining a size for a triggering geofence based on a distance between the current location of the mobile device and a particular nearest location that is farthest from the current location of the mobile device of the plurality of determined nearest locations; generating respective local geofences for the plurality of nearest locations except the particular nearest location that is farthest from the current location of the mobile device of the plurality of nearest locations; generating a triggering geofence having the determined size, the triggering geofence enclosing the current location of the mobile device; determining that the mobile device has exited the triggering geofence; and in response to determining that the mobile device has exited the triggering geofence, updating the triggering geofence.