'Add lat/lon to location references
@param rmap: the reference map of the tree'

def latlon(self, rmap):

    ATTRIBUTE = self.ATTRIBUTE
    locations = {}
    for reference in rmap:
        if ((reference.table == 'gis_location') and (len(reference.id) == 1)):
            location_id = reference.id[0]
            if (location_id not in locations):
                locations[location_id] = [reference]
            else:
                locations[location_id].append(reference)
    if locations:
        ltable = current.s3db.gis_location
        rows = current.db(ltable._id.belongs(locations.keys())).select(ltable.id, ltable.lat, ltable.lon).as_dict()
        for (location_id, row) in rows.items():
            lat = row['lat']
            lon = row['lon']
            if ((lat is not None) and (lon is not None)):
                references = locations.get(location_id, ())
                for reference in references:
                    attr = reference.element.attrib
                    attr[ATTRIBUTE.lat] = ('%.4f' % lat)
                    attr[ATTRIBUTE.lon] = ('%.4f' % lon)
    return
