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

173
Views
Marcadores de Google Maps: cómo hacer que se muestren, por favor

Tengo mi mapa en pleno funcionamiento, aunque no estoy seguro de por qué no puedo obtener ningún marcador o grupo para entrar en esto. El código JS que tengo está a continuación:

 function initMap() { var map = new google.maps.Map(document.getElementById("map"), { zoom: 12, center: { lat: 51.40219, lng: -0.16890 } }); var labels = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; } //Coordinates for the various Memorials and Cemetries listed for the corresponding Hero that will be marked on the map. // I used https://codepen.io/ahmadawais/pen/NQdWQx?editors=1010 to see how to do the below with the locations as this way it will show with the names of the memorials or cemeteries var locations = [ ['Private Richard Spearink - St Souplet British Cemetery', { lat: 50.05484, lng: 3.52440 }, 1], ['Private Frederick Spearink - Mitcham War Memorial', { lat: 51.40219, lng: -0.16890 }, 2], ['Private Frederick Spearink - Helles Memorial', { lat: 40.04597, lng: 26.17921}, 2] ]; var markers = locations.map(function(location, i) { return new google.maps.Marker({ position: location, label: labels[i % labels.length] }); }); var markerCluster = new MarkerClusterer(map, markers, { imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m' });

¿Alguien podría decirme qué necesito agregar o eliminar, ya que no estoy seguro de por qué esto no funciona?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

No estás pasando correctamente tu latitud y longitud para tus marcadores.

Su matriz de locations es una matriz de matrices de longitud fija ("tuplas"), la segunda de las cuales es un objeto de lat y lng que coincide con LatLngLiteral . Ese es el valor correcto para la position en MarkerOptions , pero en su locations.map está pasando location , que aquí es la tupla completa.

Debido a que cada entrada no es una location , he cambiado el nombre de location a locationTuple ; los nombres no le importan al código, pero deja más claro que necesitará usar locationTuple[1] (o location[1] ) para referirse a su valor para position . En ese momento, también puede usar las etiquetas como locationTuple[0] en lugar de elegir una letra arbitraria.

 var locations = [ ['Private Richard Spearink - St Souplet British Cemetery', { lat: 50.05484, lng: 3.52440 }, 1], ['Private Frederick Spearink - Mitcham War Memorial', { lat: 51.40219, lng: -0.16890 }, 2], ['Private Frederick Spearink - Helles Memorial', { lat: 40.04597, lng: 26.17921}, 2] ]; var markers = locations.map(function(locationTuple, i) { // rename return new google.maps.Marker({ position: locationTuple[1], // rename + add index 1 label: locationTuple[0] // rename + add index 0 }); });
about 4 years ago · Juan Pablo Isaza Report
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!