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

171
Views
¿Cómo creo una ventana de información que funcione y uso un detector de eventos dentro de ella?

Estoy tratando de crear una ventana de información que muestre un fragmento de texto 'this is my marker' cuando se carga el mapa, pero no se muestra. Estoy usando exactamente el mismo código del powerpoint de mi profesor, pero no sé dónde me estoy equivocando.

 function initialize(){ let mapDiv = document.getElementById('map'); let mapOptions = { center: new google.maps.LatLng(Coords.lat,Coords.lng), zoom: 4, mapTypeId: google.maps.MapTypeId.HYBRID }; let marker = new google.maps.Marker({ position: new google.maps.LatLng(40.72,-74.00), map: map, title: 'I am here!', icon: svgMarker }); var infoWindow = new google.maps.InfoWindow({content: 'This is my marker'}); google.maps.event.addListener(marker, 'click', function() { infoWindow.open(map,this); }); map = new google.maps.Map(document.getElementById("map"), mapOptions); };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Tienes la secuencia un poco mal. Está intentando agregar tanto el marcador como la ventana de información antes de haber creado el mapa. Tal vez si vuelve a secuenciar su código un poco así:

 /* assumed that a global variable exists */ let Coords={ lat:41, lng:-75 }; function initialize(){ let options = { center: new google.maps.LatLng( Coords.lat,Coords.lng ), zoom: 4, mapTypeId: google.maps.MapTypeId.HYBRID }; let map = new google.maps.Map( document.getElementById("map"), options ); let marker = new google.maps.Marker({ position: new google.maps.LatLng(40.72,-74.00), map: map, title: 'I am here!' /*, icon: svgMarker */ }); let infoWindow = new google.maps.InfoWindow( { content:'This is my marker' } ); infoWindow.open( map, marker ); google.maps.event.addListener(marker, 'click', function(e) { infoWindow.open(map,this); }); };

Para que aparezca la ventana de información cuando se carga el mapa, debe llamar al método open y, si proporciona el marcador creado previamente como segundo argumento, aparecerá en la ubicación correcta.

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!