Skip to main content

Easy way to add GoogleMaps to Flask Applications

Project description

Flask Google Maps Generic badge

Flask Estension PyPI version PyPI download month PyPI license PyPI format PyPI status PyPI pyversions

Easy to use Google Maps in your Flask application



To contribute with the project, clone it, create a virtualenv and install all of you need to dev, see below:

git clone
cd Flask-GoogleMaps
poetry use env 3.8  # just to create virtualenv at the first time
poetry shell # activate virtualenv
poetry install  # to install all for dev


To use in your project just use your dependency manager to install it, with pip is like this:

pip install flask-googlemaps

How it works

Flask-GoogleMaps includes some global functions and template filters in your Jinja environment, also it allows you to use the Map in views if needed.


in your app

from flask import Flask
from flask_googlemaps import GoogleMaps

app = Flask(__name__)

# you can set key as config
app.config['GOOGLEMAPS_KEY'] = "8JZ7i18MjFuM35dJHq70n3Hx4"

# Initialize the extension

# you can also pass the key here if you prefer
GoogleMaps(app, key="8JZ7i18MjFuM35dJHq70n3Hx4")

In template

{{googlemap("my_awesome_map", lat=0.23234234, lng=-0.234234234, markers=[(0.12, -0.45345), ...])}}

That's it! now you have some template filters and functions to use, more details in examples and screenshot below.


  • You can create the map in the view and then send to the template context
  • you can use the template functions and filters directly

1. View

from flask import Flask, render_template
from flask_googlemaps import GoogleMaps
from flask_googlemaps import Map

app = Flask(__name__, template_folder=".")

def mapview():
    # creating a map in the view
    mymap = Map(
        markers=[(37.4419, -122.1419)]
    sndmap = Map(
             'icon': '',
             'lat': 37.4419,
             'lng': -122.1419,
             'infobox': "<b>Hello World</b>"
             'icon': '',
             'lat': 37.4300,
             'lng': -122.1400,
             'infobox': "<b>Hello World from other place</b>"
    return render_template('example.html', mymap=mymap, sndmap=sndmap)

if __name__ == "__main__":
Map() Parameters
  • lat: The latitude coordinate for centering the map.
  • lng: The longitutde coordinate for centering the map.
  • zoom: The zoom level. Defaults to 13.
  • maptype: The map type - ROADMAP, SATELLITE, HYBRID, TERRAIN. Defaults to ROADMAP.
  • markers: Markers array of tuples having (lat, lng, infobox, icon). Defaults to None.
  • or markers: a list of dicts containing icon, lat, lng, infobox.
  • or markers: Markers dictionary with icon urls as keys and markers array as values.
  • varname: The instance variable name.
  • style: A string containing CSS styles. Defaults to "height:300px;width:300px;margin:0;".
  • identifier: The CSS ID selector name.
  • cls: The CSS Class selector name. Defaults to "map".
  • language: The map language. Defaults to "en".
  • region: The map region. Defaults to "US".

Also controls True or False:

  • zoom_control
  • maptype_control
  • scale_control
  • scale_control
  • streetview_control
  • rotate_control
  • fullscreen_control
  • scroll_wheel
  • collapsible (map collapses by click on varname_collapse button)
  • center_on_user_location (using HTML5 Geolocation)

2. Template

<!DOCTYPE html>
            {{"decoupled-map"|googlemap_js(37.4419, -122.1419, markers=[(37.4419, -122.1419)])}}
        <h1>Flask Google Maps Example</h1>

        <h2> Template function centered, no marker </h2>
        {{googlemap("simple-map", 37.4419, -122.1419)}}

        <h2> Template filter decoupled with single marker </h2>
        {{"decoupled-map"|googlemap_html(37.4419, -122.1419)}}

        <h2> Template function with multiple markers </h2>
        {% with map=googlemap_obj("another-map", 37.4419, -122.1419, markers=[(37.4419, -122.1419), (37.4300, -122.1400)]) %}
        {% endwith %}

        <h2> First map generated in view</h2>

        <h2> Second map generated in view</h2>
        <h3> Example for different icons in multiple markers with infoboxes</h3>



Here's an example snippet of code:

                'icon': '',
                'lat':  37.4419,
                'lng':  -122.1419,
                'infobox': "<img src='cat1.jpg' />"
                'icon': '',
                'lat': 37.4300,
                'lng': -122.1400,
                'infobox': "<img src='cat2.jpg' />"
                'icon': '',
                'lat': 37.4500,
                'lng': -122.1350,
                'infobox': "<img src='cat3.jpg' />"

Which results in something like the following map: screen shot 2015-07-29 at 2 41 52 pm

Fit all markers within bounds

Allow users to easily fit all markers within view on page load

Without bounds

def map_unbounded():
"""Create map with markers out of bounds."""
    locations = []    # long list of coordinates
    map = Map(
        markers=[(loc.latitude, loc.longitude) for loc in locations]
    return render_template('map.html', map=map)


With bounds

def map_bounded():
"""Create map with all markers within bounds."""
    locations = []    # long list of coordinates
    map = Map(
        markers=[(loc.latitude, loc.longitude) for loc in locations],
        fit_markers_to_bounds = True
    return render_template('map.html', map=map)


Run the example app

$ git clone
$ cd Flask-GoogleMaps/

If you have Poetry

$ poetry install

without poetry

$ pip install --upgrade pip
$ pip install -e .
$ pip install -r requirements.txt

Run it.

$ FLASK_GOOGLEMAPS_KEY="YourKeyHERE" FLASK_APP=examples/ flask run
running on localhost:5000 .....

Access: http://localhost:5000/ and http://localhost:5000/fullmap

Contribute with the Google Maps API

Please see this page and contribute!

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for flask-googlemaps, version 0.4.0
Filename, size File type Python version Upload date Hashes
Filename, size flask_googlemaps-0.4.0-py3-none-any.whl (14.8 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size flask_googlemaps-0.4.0.tar.gz (17.5 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page