Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

230
Visualizações
how to send longitude and latitude to javascript script from def django

I can't figure out how to replace digital longitude and latitude values with dynamic fields from postgres in javascript how to get the longitude and latitude of a particular place in this script?

<div id='map' style='width: 100%; height: 400px;'></div>
    <script>
    mapboxgl.accessToken = '{{ mapbox_access_token }}';
    var map = new mapboxgl.Map({
      container: 'map',
      style: 'mapbox://styles/mapbox/streets-v10',
      center: [20.890438, 52.256002],
      // {{venue.lat}}, {{venue.long}} How to pass fields in a similar way as all other django fields
      zoom: 9
    });
    
    var marker= new mapboxgl.Marker()
      .setLngLat([20.890438, 52.256002])
      // {{venue.lat}}, {{venue.long}}
      .addTo(map)
    </script>

All rendering functions in django. Here's how to send a specific longitude and latitude for a specific event.

def show_venue(request, venue_id):
venue = Venue.objects.get(pk=venue_id)
venue_owner = User.objects.get(pk=venue.owner)
long = Venue.objects.get(pk=venue.long)
lat = Venue.objects.get(pk=venue.lat)
#addresses = Venue.objects.all()
mapbox_access_token = 'pk.eyJ1IjoicGF2ZWxzdHJ5a2hhciIsImEiOiJjbDI2ZmJmcTkyajBwM2lscDd6aDVwOG4xIn0.15o8i7eD1qwyQcnsx2iBmg'
return render(request, 
    'events/show_venue.html', {
    'venue': venue,
    'venue_owner':venue_owner,
    #'addresses': addresses,
    'mapbox_access_token': mapbox_access_token,
    'lat':lat,
    'long':long,
    })

I will be very grateful for your help

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

In Django i would write like this

{{venue.long}} {{venue.lat}}

and in JavaScript it should be like this

['{{venue.long}}','{{venue.lat}}']
about 4 years ago · Juan Pablo Isaza Relatório

0

If the problem is the format, you can try this:

center: [{{venue.lat|floatformat:'5'}}, {{venue.long|floatformat:'5'}}]
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda