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

161
Vistas
Add multiple markers on google map using findPlaceFromQuery method

I've created a pop-up modal that shows a google map that displays a found place with the findPlaceFromQuery Method. This works, but I have tried to add multiple markers on the map with the same method but it doesn't work. I think the places have to be put in some sort of array to work properly. Do you have any ideas? I will put my code below and an screenshot of the map.

Image of the map with one marker

    let map;
    let service;
    let infowindow;
    
    function initMap() {
      const england = new google.maps.LatLng(52.3555, 1.1743);
    
      infowindow = new google.maps.InfoWindow();
      map = new google.maps.Map(document.getElementById("map_canvas"), {
        center: england,
        zoom: 20,
        mapTypeId: 'hybrid'
      });
    
      var request = {
        query: "Oliver Bonas",
        fields: ["name", "geometry"],
      };
    
      service = new google.maps.places.PlacesService(map);
      service.findPlaceFromQuery(request, (results, status) => {
        if (status === google.maps.places.PlacesServiceStatus.OK && results) {
          for (let i = 0; i < results.length; i++) {
            createMarker(results[i]);
          }
    
          map.setCenter(results[0].geometry.location);
        }
      });
    }
    
    function createMarker(place) {
      if (!place.geometry || !place.geometry.location) return;
    
      const marker = new google.maps.Marker({
        map,
        position: place.geometry.location,
        
      });
    
      google.maps.event.addListener(marker, "click", () => {
        infowindow.setContent(place.name || "");
        infowindow.open(map);
      });
    }
    
    $('#mapModal').on('show.bs.modal', function(event) {
        initMap();
        $("#location-map").css("width", "100%");
        $("#map_canvas").css("width", "100%");
        });
about 4 years ago · Santiago Gelvez
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