You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1023 B

from flask import Flask, render_template, Response, request, redirect, url_for
import folium
from geopy.geocoders import Nominatim
app = Flask(__name__)
app.config["TEMPLATES_AUTO_RELOAD"] = True
geolocator = Nominatim(user_agent="MyApp")
def get_coordinates(town):
location = geolocator.geocode(town)
return location
def save_map(zoom, latitude, longitude):
map_folium = folium.Map(
location=[latitude, longitude],
zoom_start=zoom
)
map_folium.save('templates/map.html')
return redirect(url_for("map_get"))
@app.route("/map")
def map_get():
return render_template("interactiv_map.html")
@app.get('/')
def base_get():
return render_template("index.html")
@app.post('/')
def base_post():
zoom = request.form.get("zoom")
town = request.form.get("town")
if zoom and town is not None:
save_map(zoom, get_coordinates(town).latitude, get_coordinates(town).longitude)
return redirect(url_for("map_get"))
if __name__ == '__main__':
app.run()