'Apply method.
@param r: the S3Request
@param attr: controller options for this request'

@staticmethod
def apply_method(r, **attr):

    if (r.representation == 'html'):
        T = current.T
        s3db = current.s3db
        response = current.response
        table = r.table
        tracker = S3Trackable(table, record_id=r.id)
        title = T('Check-In')
        get_vars = r.get_vars
        location_id = get_vars.get('location_id', None)
        if (not location_id):
            lat = get_vars.get('lat', None)
            if (lat is not None):
                lon = get_vars.get('lon', None)
                if (lon is not None):
                    form_vars = Storage(lat=float(lat), lon=float(lon))
                    form = Storage(vars=form_vars)
                    s3db.gis_location_onvalidation(form)
                    location_id = s3db.gis_location.insert(**form_vars)
        form = None
        if (not location_id):
            formstyle = current.deployment_settings.get_ui_formstyle()
            row = formstyle('test', 'test', 'test', 'test')
            if isinstance(row, tuple):
                tuple_rows = True
            else:
                tuple_rows = False
            form_rows = []
            comment = ''
            _id = 'location_id'
            label = LABEL(('%s:' % T('Location')))
            from s3.s3widgets import S3LocationSelector
            field = table.location_id
            value = None
            widget = S3LocationSelector(show_latlon=True)(field, value)
            row = formstyle(('%s__row' % _id), label, widget, comment)
            if tuple_rows:
                form_rows.append(row[0])
                form_rows.append(row[1])
            else:
                form_rows.append(row)
            _id = 'submit'
            label = ''
            widget = INPUT(_type='submit', _value=T('Check-In'))
            row = formstyle(('%s__row' % _id), label, widget, comment)
            if tuple_rows:
                form_rows.append(row[0])
                form_rows.append(row[1])
            else:
                form_rows.append(row)
            if tuple_rows:
                form = FORM(TABLE(*form_rows))
            else:
                form = FORM(*form_rows)
            if form.accepts(current.request.vars, current.session):
                location_id = form.vars.get('location_id', None)
        if location_id:
            tracker.set_location(location_id)
            response.confirmation = T('Checked-In    successfully!')
        response.view = 'check-in.html'
        output = dict(form=form, title=title)
        return output
    else:
        raise HTTP(415, current.ERROR.BAD_FORMAT)
