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

Ploting data from mysql DB. #71

Closed ai-abdellah closed 6 years ago

ai-abdellah commented 6 years ago

Hello how can i inject data from mysql to maps, i use this code but its not working:

users = User.query.all()
fullmap = Map(
           identifier="fullmap",
           varname="fullmap",
           style=(
               "height:100%;"
               "width:100%;"
               "top:0;"
               "left:0;"
               "position:absolute;"
               "z-index:10;"               
           ),

           lat=37.4419,
           lng=-122.1419,           

           markers=[
               {           
                   'icon': 'static/img/icons/home1.png',
                   'title': 'Adresse Home',
                   'lat': user.latitude,
                   'lng': user.longitude,
                   'infobox': (
                       "Hello I am <b style='color:#ffcc00;'>YELLOW</b>!"
                       "<h3>"user.first_name"</h3>"
                       "<img src='user.image'>"
                       "<br>Images allowed!"
                   )
               }for user in users:],

Can you help me please. Thank you

ai-abdellah commented 6 years ago

Any help please ?

rochacbruno commented 6 years ago

This should work

markers=[
               {           
                   'icon': 'static/img/icons/home1.png',
                   'title': 'Adresse Home',
                   'lat': user.latitude,
                   'lng': user.longitude,
                   'infobox': "<h3>{user.first_name}</h3><img src='{user.image}'>".format(user=user)
               }for user in users:],
ai-abdellah commented 6 years ago

hello Bruno, thank you for your answer, I tested the code but it gives me the error

raise AttributeError ('lat and lng required') AttributeError: lat and lng required

do you have any suggestion please thank you very much

rochacbruno commented 6 years ago

Your user.latitude must be empty, is that populated in the db?

ai-abdellah commented 6 years ago

the latitude and longitude fields are not empty in DB.

rochacbruno commented 6 years ago

This error is thown only if lat and lng is None https://github.com/rochacbruno/Flask-GoogleMaps/blob/master/flask_googlemaps/__init__.py#L116

ai-abdellah commented 6 years ago

actually, i checked in the DB and i found a line that contains empty value, i fixed the values and it works. thanks a lot

zheng-xing commented 5 years ago

@ai-abdellah Hi are you saving base64 encoded images in the MySQL database? Just curious why you can directly use "user.image" in "".