我正在使用一个开放源代码来使用 Google Map API,但我不知道如何调整 map 的大小。这是我的代码。请帮助我。
index.html
<body><div>{{sndmap.html}}</div></body>
main.py
@app.route('/')
def index():
sndmap = Map(
identifier="sndmap",
varname="sndmap",
lat=37.4419,
lng=-122.1419,
markers=[(37.4419, -122.1419), (37.4500, -122.1350), (37.4300, -122.1400, "Hello World")]
)
return render_template('index.html', sndmap=sndmap, GOOGLEMAPS_KEY=request.args.get('apikey'))
最佳答案
您可以轻松地包含内联样式,但添加样式表在很大程度上被认为是最易于维护的方法。
这是通过给你想要的标签一个类来完成的。然后将 css 样式表链接到您的 html 并根据需要更新 css。
我已经包括了一个例子。
projectroot/index.html
<html lang="en">
<head>
<link rel="stylesheet" type="text/css"
href="{{ url_for('static', filename='style/style.css') }}">
</head>
<!-- Other html -->
<body>
<div class="google-map">
{{ sndmap.html }}
</div>
</body>
<!-- Other html -->
</html>
projectroot/static/styles/style.css
/* More css */
.google-map {
max-width: 500px;
max-height: 200px;
}
/* More css */
这不应该逐字复制,因为您需要尝试使用确切的样式来实现您想要的外观。通过标准 css 的自定义选项数量是无穷无尽的。我建议查找常见模式并处理您喜欢的内容。
关于python - 我怎样才能在 flask 中调整谷歌地图的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60096189/