Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

90
Views
Google Maps generado dinámicamente mostrando solo un mapa en lugar de múltiples

Así que tengo un botón de búsqueda que muestra dinámicamente los hoteles. Quiero junto a ellos Quiero mostrar un mapa. Por el momento tengo la misma latitud y longitud para todos los hoteles, así que espero ver el mismo mapa. Sin embargo, actualmente solo veo un mapa generado para el primer hotel. El resto están en blanco. ¿Qué estoy haciendo mal?

Aquí está el código:

 <script async defer src="https://maps.googleapis.com/maps/api/js?key=API_KEY"></script> <script th:inline="javascript"> function initMap() { fetch('http://localhost:8080/accommodations') .then(response => { return response.json() }) .then((data) => { console.dir(data) data.forEach(function (hotel) { console.log(hotel); const coords = { lat: parseFloat(hotel.lat), lng: parseFloat(hotel.lng) }; console.log(coords); const map = new google.maps.Map( document.getElementById('map'), {zoom: 15, center: coords}); const marker = new google.maps.Marker({position: coords, map: map}); }) }) } </script>
 <script type="text/javascript" th:inline="javascript"> document.getElementById('showAll').addEventListener('click', showAll); function showAll() { // window.addEventListener('DOMContentLoaded', (event) => { fetch('http://localhost:8080/accommodations') .then(response => { return response.json() }) .then((data) => { console.dir(data) let output = '<h2 style="padding-left: 27px"> Search Results </h2>' data.forEach(function (hotel) { console.dir(hotel) initMap(); output += ` <div class="col-lg-3 px-0" id="map"></div> `; }); document.getElementById('output').innerHTML = output }) }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!