Create a Flask web application that integrates with the Google Maps API to display a map centered at a user-provided location. The application should also allow users to place markers on the map and save their locations to a SQLite database.
PLAINFORMAT
from flask import Flask, render_template, request, jsonify
from flask_sqlalchemy import SQLAlchemy
import requests

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///markers.db'
db = SQLAlchemy(app)

class Marker(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    lat = db.Column(db.Float, nullable=False)
    lng = db.Column(db.Float, nullable=False)

API_KEY = 'YOUR_API_KEY'

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/map', methods=['POST'])
def map():
    address = request.form['address']
    response = requests.get(f'https://maps.googleapis.com/maps/api/geocode/json?address={address}&key={API_KEY}')
    data = response.json()
    if data['status'] == 'OK':
        lat_lng = data['results'][0]['geometry']['location']
        return render_template('map.html', lat=lat_lng['lat'], lng=lat_lng['lng'], api_key=API_KEY)
    else:
        return "Error: Unable to find location."

@app.route('/save_marker', methods=['POST'])
def save_marker():
    lat = request.form['lat']
    lng = request.form['lng']
    marker = Marker(lat=lat, lng=lng)
    db.session.add(marker)
    db.session.commit()
    return jsonify({'result': 'success'})

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