Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
3 Відповіді
12035 Переглядів

Hello everyone, I am developing a website with controllers, I want to show a map with google maps api javascript for each client, the coordinates of the clients I have in res.partner, how can I pass this data to javascript?. For example

I have next code in the xml and works but the latitude and longitude is fixed

<div id="map"></div>
<script src="https://maps.googleapis.com/maps/api/js?key=Api&amp;callback=initMap"

async="async" defer="defer"></script>
<script>
  var map;
  function initMap() {
  map = new google.maps.Map(document.getElementById('map'), {
  center: {lat: 19.3620379, lng: -99.130065},
  zoom: 12,
  });
  var marker = new google.maps.Marker({
position: {lat:  19.3812391, lng: -99.2041034},
  map: map,
  title: 'Lueste'
  });
  }
</script>
I want the coordinates to be obtained from the database, between several attempts, I tried with something like this.

position: {lat:  <span t-value="delivery.partner_latitude()"/>,  lng:<span t-value="delivery.partner_longitude()"/> },

Or

position: {lat: $( "delivery.partner_latitude" ).val(), lng: $( "delivery.partner_longitude" ).val()},
Delivery is label from my model.



class Logistics(http.Controller):

@http.route('/logistics/token=<model("logistics.concretedelivery"):delivery>', type='http', auth='public', website=True)
def logis_home_token(self, delivery, **kwargs):
return request.render('logistics.logistics_website', {
"delivery": delivery})


Do you have any suggestions on how to pass the parameters to it? Thank you very much for reading and giving me advice.
Аватар
Відмінити
Автор Найкраща відповідь

It's done, I used qweb. The code is this.

var latitude_partner = <t t-esc="delivery.partner_latitude"/>;
var longitude_partner = <t t-esc="delivery.partner_longitude"/>;
var marker_partner = new google.maps.Marker({
position: {lat: latitude_partner, lng: longitude_partner},
map: map,
title: 'Lueste'
});
Аватар
Відмінити
Найкраща відповідь

Hey Omar Rodrigues Torres, Your answer seems to be the solution I am looking for too, could you please tell me how did you get working the gmap using the QWeb, I was unable to pass dynamic lat and long to script tag inside XML. Thanks for the help in advance.

Аватар
Відмінити
Автор

Hi, if you have lat and long in a specific model, you can use those coordenates for use gmap, you need a controller that pass those params. For example

@http.route('path', type='http', auth='public')
def url(self, **rec):
model = request.env['sale.order'].sudo().browse(id)
return request.render('path.qweb_id', {'model ': model})

After you need a qweb, in a xml file

<template id="remision_website" name="Remisión">
<t t-call="website.layout">

<script src="https://maps.googleapis.com/maps/api/js?key=Api&amp;callback=initMap" async="async" defer="defer"></script>
<script>
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 19.3620379, lng: -99.130065},
zoom: 12,
});

var latitude_partner = <t t-esc="model.latitude_field"/>;
var longitude_partner = <t t-esc="model.longitude_field"/>;
var marker_partner = new google.maps.Marker({
position: {lat: latitude_partner, lng: longitude_partner},
map: map
});
}
</script>
<div id="map"></div>
</t>
</template>

Найкраща відповідь

Hey! Do you know how to do it but inverse way? Get Javascript variable and pass it into odoo template? Thanks!

Аватар
Відмінити
Автор

You must use POST method in the controller, for example if you use box and the buttom send, each box is necesary have a key, and the controller is some similar to this

@http.route('/route/=<model("model.model"):feed>', type='http', auth="public", website=True)

def feedback_website_website(self, feed, **post):

if post.get('pregunta_1') or post.get('pregunta_2') or post.get('pregunta_5') or post.get('pregunta_10') or post.get('pregunta_11') or post.get('comentarios'):

for aux in range(10):

contador=str(aux+1)

exec("feed.pregunta_"+contador+" = post.get('pregunta_"+contador+"')")

feed.comentarios = post.get('comentarios_descrip')

feed.status_feedback = True

return request.redirect('/logistics/feedback/token='+str(feed.id)+'?submitted=1')

Related Posts Відповіді Переглядів Дія
0
лип. 24
1476
1
лют. 16
6525
4
бер. 25
3543
2
серп. 24
1457
0
трав. 23
1758