Skip to content

Commit 91c8171

Browse files
committed
add a form to get APIkey
1 parent feedbac commit 91c8171

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

examples/example.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@
77
app = Flask(__name__, template_folder="templates")
88

99
# you can set key as config
10-
app.config['GOOGLEMAPS_KEY'] = "AIzaSyAZzeHhs-8JZ7i18MjFuM35dJHq70n3Hx4"
10+
#app.config['GOOGLEMAPS_KEY'] = "AIzaSyDP0GX-Wsui9TSDxtFNj2XuKrh7JBTPCnU"
1111

1212
# you can also pass key here
13-
GoogleMaps(app, key="AIzaSyAZzeHhs-8JZ7i18MjFuM35dJHq70n3Hx4")
13+
GoogleMaps(
14+
app,
15+
#key="AIzaSyDP0GX-Wsui9TSDxtFNj2XuKrh7JBTPCnU"
16+
)
17+
18+
# NOTE: this example is using a form to get the apikey
1419

1520

1621
@app.route("/")
@@ -306,7 +311,7 @@ def mapview():
306311
'infobox': 'This is a polyline'
307312
}]
308313
)
309-
314+
310315
clickmap = Map(
311316
identifier="clickmap",
312317
varname="clickmap",
@@ -332,7 +337,8 @@ def mapview():
332337
movingmarkers=movingmarkers,
333338
collapsible=collapsible,
334339
infoboxmap=infoboxmap,
335-
clickmap=clickmap
340+
clickmap=clickmap,
341+
GOOGLEMAPS_KEY=request.args.get('apikey')
336342
)
337343

338344

@@ -380,14 +386,20 @@ def fullmap():
380386
# maptype = "TERRAIN",
381387
# zoom="5"
382388
)
383-
return render_template('example_fullmap.html', fullmap=fullmap)
389+
return render_template(
390+
'example_fullmap.html',
391+
fullmap=fullmap,
392+
GOOGLEMAPS_KEY=request.args.get('apikey')
393+
)
384394

385395
@app.route('/clickpost/', methods=['POST'])
386396
def clickpost():
387-
# Now lat and lon can be accessed as:
388-
Lat = request.form['lat']
389-
lng = request.form['lng']
390-
return "ok"
391-
397+
# Now lat and lon can be accessed as:
398+
lat = request.form['lat']
399+
lng = request.form['lng']
400+
print(lat)
401+
print(lng)
402+
return "ok"
403+
392404
if __name__ == "__main__":
393405
app.run(debug=True, use_reloader=True)

examples/templates/example.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
<body>
2323
<h1>Flask Google Maps Example</h1>
2424

25+
Provide your Google Maps API Key to test it.
26+
Get you APIKEY in <a href="https://cloud.google.com/maps-platform/?apis=maps">https://cloud.google.com/maps-platform/?apis=maps</a>
27+
<form action="." method="GET">
28+
<input type="text" name="apikey" id="apikey"/><input type="submit" value="load"/>
29+
</form>
30+
<hr>
31+
2532
<h2> Template function centered, no marker </h2>
2633
{{googlemap("simple-map", 37.4419, -122.1419, varname="simplemap")}}
2734
<code>

examples/templates/example_fullmap.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
</head>
1010
<body>
1111
<h1>Flask Google Maps Full Map Example</h1>
12+
Provide your Google Maps API Key to test it.
13+
Get you APIKEY in <a href="https://cloud.google.com/maps-platform/?apis=maps">https://cloud.google.com/maps-platform/?apis=maps</a>
14+
<form action="." method="GET">
15+
<input type="text" name="apikey" id="apikey"/><input type="submit" value="load"/>
16+
</form>
17+
<hr>
1218
{{ fullmap.html }}
1319

1420
</body>

0 commit comments

Comments
 (0)