Flask_GoogleMap在信息框中显示base64图像

时间:2018-12-13 20:44:22

标签: flask google-maps-markers base64url

GoogleMaps(https://github.com/rochacbruno/Flask-GoogleMaps)以在Google地图中显示图像。

从MySQL数据库检索图像并将其转换为base64编码。但是,我遇到这样的错误:

TypeError:“十进制”类型的对象不可JSON序列化

我试图寻找解决方案,但没有成功。 有人可以给我一些建议吗?

谢谢!

Python3中的相关代码如下:

@app.route('/fullmap')
def fullmap():
    db = MySQLdb.connect(user='root', password='', host='127.0.0.1', database='userprofile')
    query = ("SELECT lat, lng, user_avatar FROM user")
    cursor = db.cursor()
    cursor.execute(query)

    for (lat, lng, user_avatar) in cursor:
        icon = '//maps.google.com/mapfiles/ms/icons/green-dot.png'
        b64_content = base64.b64encode(user_avatar)
        dataurl = 'data:image/jpeg;base64,' + b64_content.decode()
        srcurl = "<img src='" + dataurl + "' />"
        markers.append({'icon': icon, 'lat': lat, 'lng': lng, 'infobox': srcurl})

    fullmap = Map(
        identifier="fullmap",
        varname="fullmap",
        style=(
            "height:100%;"
            "width:100%;"
            "top:0;"
            "left:0;"
            "position:absolute;"
            "z-index:200;"
        ),
        lat=37.3,
        lng=127.0,
        markers=markers
    )
    return render_template(
        'example_fullmap.html',
        fullmap=fullmap,
        GOOGLEMAPS_KEY=request.args.get('apikey')
    )

0 个答案:

没有答案