'Set the current location of instance(s) (at the given time)
@param location: the location (as Row or record ID)
@param timestmp: the datetime of the presence (defaults to current time)
@return: location'

def set_location(self, location, timestmp=None):

    ptable = current.s3db[PRESENCE]
    if (timestmp is None):
        timestmp = datetime.utcnow()
    if isinstance(location, S3Trackable):
        location = location.get_base_location()
    if isinstance(location, Rows):
        location = location.first()
    if isinstance(location, Row):
        if ('location_id' in location):
            location = location.location_id
        else:
            location = location.id
    data = dict(location_id=location, timestmp=timestmp)
    for r in self.records:
        if (TRACK_ID not in r):
            if (len(self.records) > 1):
                trackable = S3Trackable(record=r)
            else:
                trackable = self
            trackable.set_base_location(location)
        elif r[TRACK_ID]:
            data.update({TRACK_ID: r[TRACK_ID]})
            ptable.insert(**data)
            self.__update_timestamp(r[TRACK_ID], timestmp)
    return location
