flask-extensions / Flask-GoogleMaps

Easy way to add GoogleMaps to Flask applications. maintainer: @getcake
https://flask-googlemaps.com
MIT License
647 stars 196 forks source link

[bug]Maps not loading to page #146

Open phukeo opened 3 years ago

phukeo commented 3 years ago

I can't get the example maps to load to the page 'example.html'. When I go to my API metrics page on the Google Cloud Platform the number of calls to my API is not changing.

I have tested my API key with a standard JS request and it is increasing and therefore the key is working.

I have the following code on my app.py and my 'example.html' is exactly as is given in the repo front page.

Any ideas? Feedback is greatly appreciated.

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

app = Flask(__name__)
app.config['GOOGLEMAPS_KEY'] = "my_API_key"
GoogleMaps(app, key="my_API_key")

@app.route("/")
def mapview():
    # creating a map in the view
    mymap = Map(
        identifier="view-side",
        lat=37.4419,
        lng=-122.1419,
        markers=[(37.4419, -122.1419)]
    )
    sndmap = Map(
        identifier="sndmap",
        lat=37.4419,
        lng=-122.1419,
        markers=[
          {
             'icon': 'http://maps.google.com/mapfiles/ms/icons/green-dot.png',
             'lat': 37.4419,
             'lng': -122.1419,
             'infobox': "<b>Hello World</b>"
          },
          {
             'icon': 'http://maps.google.com/mapfiles/ms/icons/blue-dot.png',
             '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__":
    app.run(debug=True)
plusangel commented 3 years ago

I have the same issue like @phukeo Google Maps API key works on a simple (hello world) page but not with Flask-googlemap plugin. I use version 4.1

phukeo commented 3 years ago

Just FYI I masked my API details in my original comment. As mentioned before my API key is working for other applications

plusangel commented 3 years ago

The solution is to use version 0.4.1.1, downloading the code from the releases page and not install it using pip which supports the previous version 0.4.1 @phukeo

getcake commented 3 years ago

Just wanted to say I'm encountering the same error. will try @plusangel 's solution.

edit: worked like a charm :)

Bhumika-Kothwal commented 3 years ago

Just wanted to say I'm encountering the same error. will try @plusangel 's solution.

edit: worked like a charm :)

Could you please provide the link to the release page of version 0.4.1.1

plusangel commented 3 years ago

Hello @Bhumika-Kothwal This is your place for the release

Mengyujun commented 3 years ago

Hello @Bhumika-Kothwal This is your place for the release

Thankyou! You helped me solve the probblem

yusef1990 commented 2 years ago

Just wanted to say I'm encountering the same error. will try @plusangel 's solution.

edit: worked like a charm :)

I am sorry but I am bit of a noob in python, how do I install it without going through pip? Thanks in advance!

getcake commented 2 years ago

No worries at all! You can find that specific release here and download a zip of the source.

plusangel mentioned not using pip to install, but this turned out to work fine for my use.

Just specify the directory of the folder when installing, and use a virtual environment if you plan on working with other versions. Also keep in mind the project now fully supports poetry.

pip install ~/bla/Flask-GoogleMaps-0.4.1.1/

yusef1990 commented 2 years ago

No worries at all! You can find that specific release here and download a zip of the source.

plusangel mentioned not using pip to install, but this turned out to work fine for my use.

Just specify the directory of the folder when installing, and use a virtual environment if you plan on working with other versions. Also keep in mind the project now fully supports poetry.

pip install ~/bla/Flask-GoogleMaps-0.4.1.1/

As you said before, worked like a charm! :) thank you so much!

catscrdl commented 1 year ago

If you're trying to do this in docker, you can add something like

# install python dependencies
RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt
RUN wget https://github.com/flask-extensions/Flask-GoogleMaps/archive/refs/tags/0.4.1.1.zip -O flask-googlemaps.zip
RUN pip install flask-googlemaps.zip

As I ran into this issue earlier today.