我正在尝试使用flask sqlite通过GoogleMaps api呈现数据
当前在my views.py文件中,我有以下方法:
@app.route('/googlemap.html', methods=['POST'])
def map():
if request.method == 'POST':
conn = sqlite3.connect(database.db)
cur = conn.cursor()
c_lat = cur.execute("SELECT latitude FROM table")
c_long = cur.execute("SELECT longitude FROM table")
return render_template(content=render_template('googlemap.html', lat=c_lat.fetchall(), long=c_long.fetchall()))
在GoogleMapsAPI示例中,他们手动添加每个点
function getPoints() {
return [
new google.maps.LatLng(37.782551, -122.445368),
new google.maps.LatLng(37.782745, -122.444586)
];
但是我想查询每个数据,并将数据库中的每个纬度和经度添加到我的googlemap.html文件中
<script>
function getPoints() {
var points = [];
//Add each latitude into points array and return and array off all points
return points
}
</script>
但是我不知道如何将views.py文件中的lat和long变量添加到代码的javascript部分
您可以这样做,将数据库查询结果映射到JavaScript
因为您没有使用ajax,所以需要首先向某个标记添加数据, 通常我们在HTML文件中添加一个元标记
例如:
现在在JS代码中,您可以使用jquery访问这些数据
您现在可以在控制台中打印一些\u数据,并进行检查
相关问题 更多 >
编程相关推荐