Google地图与Dash python web框架的集成

2024-06-16 17:32:32 发布

您现在位置:Python中文网/ 问答频道 /正文

在其中一个需求中,我需要将GoogleMap与Dash框架集成,并在地图上单击-检索lat、long和address(在地图上单击事件)

我能够使用GoogleAPI和flask框架通过java脚本检索相同的内容,java脚本根据地图点击事件给出Lat、Long和Address,并呈现GoogleMap

以下是在flask framework中使用的python代码:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import json
from flask import Flask, render_template, request

app = Flask(__name__)

@app.route('/map', methods=['GET', 'POST'])
def map():
location = {}
if request.method == "POST":
    location = request.get_json()
    # latitude = location['latitude']
    # longitude = location['longitude']
    print(location);
return render_template('map.html')

if __name__ == '__main__':
app.run(debug = True) # run app

任何关于如何使用Dash框架实现相同目标的指导都会非常有用。如果需要,我也可以共享JS脚本代码


Tags: 代码import脚本框架jsonappflaskmap