Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

200
Vistas
Adding markers google maps using sql db in django

How can I add multiple markers to my Google map using data from database?

My js code:

function initMap() {
  const myLatLng = { lat: -25.363, lng: 131.044 };
  const map = new google.maps.Map(document.getElementById("map"), {
    zoom: 4,
    center: myLatLng,
  });

  new google.maps.Marker({
    position: myLatLng,
    map,
    title: "Hello World!",
  });
}

// Adds a marker to the map and push to the array.
function addMarker(position) {
  marker_f = Markers.objects.all()
  const marker = new google.maps.Marker({
    Markers from models,
    map,
  });

  markers.push(marker);
}

My models.py code:

from django.db import models
from django.core.validators import MaxValueValidator, MinValueValidator
# Create your models here.
class Markers(models.Model):
    area = models.CharField(max_length=100)
    latitude = models.FloatField(
        validators=[MinValueValidator(-90), MaxValueValidator(90)],
)
    longitude = models.FloatField(
        validators=[MinValueValidator(-180), MaxValueValidator(180)],
)

Tutorials used for generating this code:

https://developers.google.com/maps/documentation/javascript/examples/marker-remove https://developers.google.com/maps/documentation/javascript/examples/marker-simple

I don't want to hardcode my coords in js like in the example below, I would like to add them via my admin page in django with models.py variable to show markers on my map in html https://developers.google.com/maps/documentation/javascript/examples/icon-complex

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda