From b118d7136679f25e9dbb3b0ff3f9923c5f8c2850 Mon Sep 17 00:00:00 2001 From: kprftw Date: Sun, 8 Sep 2024 19:27:19 -0600 Subject: [PATCH] reverse geocoding a la hora de guardar en la DB --- app.py | 6 +++++- templates/index.html | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index 8ee52bb..5a56afb 100644 --- a/app.py +++ b/app.py @@ -12,7 +12,9 @@ from wtforms import StringField, FileField, SubmitField, DateTimeField, SelectFi from wtforms.validators import DataRequired, Length import requests from config import Config +from geopy.geocoders import Nominatim +geolocator = Nominatim(user_agent="Bachemapa @ baches.qro.mx") def create_app(config=Config): app = Flask(__name__) app.config.from_object(config) @@ -91,8 +93,10 @@ def create_app(config=Config): 'lng': request.form['lng'], 'typeofpin': request.form['typeofpin'], 'added_by': current_user.id, - 'description': request.form['description'] + 'description': request.form['description'], + 'address': str(geolocator.reverse(str(request.form['lat'])+ ", "+request.form['lng'])) } + print(geolocator.reverse(str(request.form['lat'])+ ", "+request.form['lng'])) mongo.db.pins.insert_one(pin) flash('¡Gracias por tu aportación!') return redirect(url_for('index')) diff --git a/templates/index.html b/templates/index.html index fc9757e..6a86e4a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -38,7 +38,7 @@ iconSize:[10,10], iconAnchor:[5,5], }); - markerCluster.addLayer(L.marker([{{ pin.lat }}, {{ pin.lng }}], {icon: icon}).bindPopup("{{ pin.description }}

Fecha del reporte: {{pin.time}}


")); + markerCluster.addLayer(L.marker([{{ pin.lat }}, {{ pin.lng }}], {icon: icon}).bindPopup("{{ pin.description }}{% if pin.address %}
{{pin.address}}{% endif %}

Fecha del reporte: {{pin.time}}


")); //markerCluster.addlayer( //L.marker([{{ pin.lat }}, {{ pin.lng }}], {icon: icon}).addTo(map)