'Function to create an OpenGeoSMS
@param: location_id - reference to record in gis_location table
@param: code - the type of OpenGeoSMS:
S = Sahana
SI = Incident Report
ST = Task Dispatch
@param: map: "google" or "osm"
@param: text - the rest of the message
Returns the formatted OpenGeoSMS or None if it can\'t find
an appropriate location'

@staticmethod
def prepare_opengeosms(location_id, code='S', map='google', text=''):

    if (not location_id):
        return text
    db = current.db
    s3db = current.s3db
    table = s3db.gis_location
    query = (table.id == location_id)
    location = db(query).select(table.lat, table.lon, limitby=(0, 1)).first()
    if (not location):
        return text
    lat = location.lat
    lon = location.lon
    if ((lat is None) or (lon is None)):
        return text
    code = ('GeoSMS=%s' % code)
    if (map == 'google'):
        url = ('http://maps.google.com/?q=%f,%f' % (lat, lon))
    elif (map == 'osm'):
        url = ('http://openstreetmap.org?mlat=%f&mlon=%f&zoom=14' % (lat, lon))
    opengeosms = ('%s&%s\n%s' % (url, code, text))
    return opengeosms
