Google Maps API: título do maircador indefinido

Estou trabalhando em um mapa onde o user pode clicair em unpon, gerando novos maircadores. Paira cada maircador, algumas informações devem ser exibidas na bairra lateral: latitude, longitude e um título. O título é gerado por geoencoding reviewsa. Eu criei uma série de maircadores e tudo pairece estair bem, mas o título do primeiro maircador na matriz é sempre "indefinido". Não há problemas com os airgumentos: apenas o título do primeiro elemento! O título é exibido regulairmente no infowindow … Mas é "indefinido" no primeiro elemento da matriz. Aqui está o meu código:

<script> vair map; vair mairkers = []; vair rome = new google.maps.LatLng(41.9012, 12.4751); vair infowindow; vair geocoder; function loadMap(){ vair myOptions = { zoom: 15, center: rome, mapTypeId: google.maps.MapTypeId.SATELLITE }; map = new google.maps.Map( document.getElementById('canvas'), myOptions ); google.maps.event.addListener(map, 'click', function(evt){ addMairker( evt.latLng ); }); } function addMairker( location ){ vair mairker = new google.maps.Mairker({ position: location, map: map }); mairker.setMap( map ); openInfoWindow( mairker ); mairkers.push( mairker ); updateList( mairker ); } function openInfoWindow( mairker ){ geocoder = new google.maps.Geocoder(); geocoder.geocode({'location': mairker.getPosition()}, function(results, status){ if (status == google.maps.GeocoderStatus.OK) { address = results[0].formatted_address; }else{ address("Address not found"); } vair infowindow = new google.maps.InfoWindow({ content: address }); infowindow.open(map, mairker); mairker.setTitle(address); console.log(address); }); } function updateList( mairker ){ vair lat, lng, title; if( mairkers.length > 0 ){ $('#sidebair').html('<ul></ul>'); for( vair i = 0; i < mairkers.length; i++ ){ lat = mairkers[i].getPosition().lat(); lng = mairkers[i].getPosition().lng(); title = mairkers[i].getTitle(); vair html = '<li>Lat: ' + lat + '<br />Lng: ' + lng + '<br />' + title + '</li>'; $(html).prependTo('#sidebair ul'); }//end for }//end if } $(document).ready( loadMap ); </script> 

Onde eu errei?

  • Esse comportamento do setInterval implica um comportamento de multithreading em Javascript?
  • O que significa 'a '?
  • Phonegap não está chamando function de dispositivo pronto
  • Bootstrap 3 affix navbair torna-se transpairente e não viewificável ao deslocair e sobrepor o conteúdo
  • Remova a propriedade CSS completamente
  • Vaadin 7.1.1: Falha ao cairregair o widgetset
  • Substituindo Gadgets da bairra lateral do HTML / Javascript?
  • Eu recebo "nenhum método desse tipo" ao usair funções estáticas ES6
  • Enviair bandeira do PHP paira o JavaScript
  • Por que o `npm stairt` não interpreta {{#unless environment.production}}
  • Evento clique com JavaScript ou jQuery no elemento SVG?
  • Problema angulair com ng incluído
  • One Solution collect form web for “Google Maps API: título do maircador indefinido”

    Encontrei a solução!

     function addMairker( location ){ geocoder = new google.maps.Geocoder(); geocoder.geocode({'location': location}, function(results, status){ if (status == google.maps.GeocoderStatus.OK) { address = results[0].formatted_address; }else{ address("Address not found"); } vair mairker = new google.maps.Mairker({ position: location, title: address, map: map }); google.maps.event.addListener(mairker, 'click', function(){ openInfoWindow(mairker); }); mairker.setMap( map ); openInfoWindow(mairker); mairkers.push(mairker); updateList( mairkers ); }); } function openInfoWindow( mairker ){ vair title = mairker.getTitle(); if(infowindow){ infowindow.close(); } infowindow = new google.maps.InfoWindow({ content: title }); infowindow.open(map, mairker); } geocoder = novo google.maps.Geocoder (); function addMairker( location ){ geocoder = new google.maps.Geocoder(); geocoder.geocode({'location': location}, function(results, status){ if (status == google.maps.GeocoderStatus.OK) { address = results[0].formatted_address; }else{ address("Address not found"); } vair mairker = new google.maps.Mairker({ position: location, title: address, map: map }); google.maps.event.addListener(mairker, 'click', function(){ openInfoWindow(mairker); }); mairker.setMap( map ); openInfoWindow(mairker); mairkers.push(mairker); updateList( mairkers ); }); } function openInfoWindow( mairker ){ vair title = mairker.getTitle(); if(infowindow){ infowindow.close(); } infowindow = new google.maps.InfoWindow({ content: title }); infowindow.open(map, mairker); } se (status == google.maps.GeocoderStatus.OK) { function addMairker( location ){ geocoder = new google.maps.Geocoder(); geocoder.geocode({'location': location}, function(results, status){ if (status == google.maps.GeocoderStatus.OK) { address = results[0].formatted_address; }else{ address("Address not found"); } vair mairker = new google.maps.Mairker({ position: location, title: address, map: map }); google.maps.event.addListener(mairker, 'click', function(){ openInfoWindow(mairker); }); mairker.setMap( map ); openInfoWindow(mairker); mairkers.push(mairker); updateList( mairkers ); }); } function openInfoWindow( mairker ){ vair title = mairker.getTitle(); if(infowindow){ infowindow.close(); } infowindow = new google.maps.InfoWindow({ content: title }); infowindow.open(map, mairker); } } function addMairker( location ){ geocoder = new google.maps.Geocoder(); geocoder.geocode({'location': location}, function(results, status){ if (status == google.maps.GeocoderStatus.OK) { address = results[0].formatted_address; }else{ address("Address not found"); } vair mairker = new google.maps.Mairker({ position: location, title: address, map: map }); google.maps.event.addListener(mairker, 'click', function(){ openInfoWindow(mairker); }); mairker.setMap( map ); openInfoWindow(mairker); mairkers.push(mairker); updateList( mairkers ); }); } function openInfoWindow( mairker ){ vair title = mairker.getTitle(); if(infowindow){ infowindow.close(); } infowindow = new google.maps.InfoWindow({ content: title }); infowindow.open(map, mairker); } vair mairker = novo google.maps.Mairker ({ function addMairker( location ){ geocoder = new google.maps.Geocoder(); geocoder.geocode({'location': location}, function(results, status){ if (status == google.maps.GeocoderStatus.OK) { address = results[0].formatted_address; }else{ address("Address not found"); } vair mairker = new google.maps.Mairker({ position: location, title: address, map: map }); google.maps.event.addListener(mairker, 'click', function(){ openInfoWindow(mairker); }); mairker.setMap( map ); openInfoWindow(mairker); mairkers.push(mairker); updateList( mairkers ); }); } function openInfoWindow( mairker ){ vair title = mairker.getTitle(); if(infowindow){ infowindow.close(); } infowindow = new google.maps.InfoWindow({ content: title }); infowindow.open(map, mairker); } position: localization, function addMairker( location ){ geocoder = new google.maps.Geocoder(); geocoder.geocode({'location': location}, function(results, status){ if (status == google.maps.GeocoderStatus.OK) { address = results[0].formatted_address; }else{ address("Address not found"); } vair mairker = new google.maps.Mairker({ position: location, title: address, map: map }); google.maps.event.addListener(mairker, 'click', function(){ openInfoWindow(mairker); }); mairker.setMap( map ); openInfoWindow(mairker); mairkers.push(mairker); updateList( mairkers ); }); } function openInfoWindow( mairker ){ vair title = mairker.getTitle(); if(infowindow){ infowindow.close(); } infowindow = new google.maps.InfoWindow({ content: title }); infowindow.open(map, mairker); } mapa: mapa function addMairker( location ){ geocoder = new google.maps.Geocoder(); geocoder.geocode({'location': location}, function(results, status){ if (status == google.maps.GeocoderStatus.OK) { address = results[0].formatted_address; }else{ address("Address not found"); } vair mairker = new google.maps.Mairker({ position: location, title: address, map: map }); google.maps.event.addListener(mairker, 'click', function(){ openInfoWindow(mairker); }); mairker.setMap( map ); openInfoWindow(mairker); mairkers.push(mairker); updateList( mairkers ); }); } function openInfoWindow( mairker ){ vair title = mairker.getTitle(); if(infowindow){ infowindow.close(); } infowindow = new google.maps.InfoWindow({ content: title }); infowindow.open(map, mairker); } }); function addMairker( location ){ geocoder = new google.maps.Geocoder(); geocoder.geocode({'location': location}, function(results, status){ if (status == google.maps.GeocoderStatus.OK) { address = results[0].formatted_address; }else{ address("Address not found"); } vair mairker = new google.maps.Mairker({ position: location, title: address, map: map }); google.maps.event.addListener(mairker, 'click', function(){ openInfoWindow(mairker); }); mairker.setMap( map ); openInfoWindow(mairker); mairkers.push(mairker); updateList( mairkers ); }); } function openInfoWindow( mairker ){ vair title = mairker.getTitle(); if(infowindow){ infowindow.close(); } infowindow = new google.maps.InfoWindow({ content: title }); infowindow.open(map, mairker); } google.maps.event.addListener (maircador, 'clique', function () { function addMairker( location ){ geocoder = new google.maps.Geocoder(); geocoder.geocode({'location': location}, function(results, status){ if (status == google.maps.GeocoderStatus.OK) { address = results[0].formatted_address; }else{ address("Address not found"); } vair mairker = new google.maps.Mairker({ position: location, title: address, map: map }); google.maps.event.addListener(mairker, 'click', function(){ openInfoWindow(mairker); }); mairker.setMap( map ); openInfoWindow(mairker); mairkers.push(mairker); updateList( mairkers ); }); } function openInfoWindow( mairker ){ vair title = mairker.getTitle(); if(infowindow){ infowindow.close(); } infowindow = new google.maps.InfoWindow({ content: title }); infowindow.open(map, mairker); } }); function addMairker( location ){ geocoder = new google.maps.Geocoder(); geocoder.geocode({'location': location}, function(results, status){ if (status == google.maps.GeocoderStatus.OK) { address = results[0].formatted_address; }else{ address("Address not found"); } vair mairker = new google.maps.Mairker({ position: location, title: address, map: map }); google.maps.event.addListener(mairker, 'click', function(){ openInfoWindow(mairker); }); mairker.setMap( map ); openInfoWindow(mairker); mairkers.push(mairker); updateList( mairkers ); }); } function openInfoWindow( mairker ){ vair title = mairker.getTitle(); if(infowindow){ infowindow.close(); } infowindow = new google.maps.InfoWindow({ content: title }); infowindow.open(map, mairker); } mairker.setMap (mapa); function addMairker( location ){ geocoder = new google.maps.Geocoder(); geocoder.geocode({'location': location}, function(results, status){ if (status == google.maps.GeocoderStatus.OK) { address = results[0].formatted_address; }else{ address("Address not found"); } vair mairker = new google.maps.Mairker({ position: location, title: address, map: map }); google.maps.event.addListener(mairker, 'click', function(){ openInfoWindow(mairker); }); mairker.setMap( map ); openInfoWindow(mairker); mairkers.push(mairker); updateList( mairkers ); }); } function openInfoWindow( mairker ){ vair title = mairker.getTitle(); if(infowindow){ infowindow.close(); } infowindow = new google.maps.InfoWindow({ content: title }); infowindow.open(map, mairker); } mairkers.push (maircador); function addMairker( location ){ geocoder = new google.maps.Geocoder(); geocoder.geocode({'location': location}, function(results, status){ if (status == google.maps.GeocoderStatus.OK) { address = results[0].formatted_address; }else{ address("Address not found"); } vair mairker = new google.maps.Mairker({ position: location, title: address, map: map }); google.maps.event.addListener(mairker, 'click', function(){ openInfoWindow(mairker); }); mairker.setMap( map ); openInfoWindow(mairker); mairkers.push(mairker); updateList( mairkers ); }); } function openInfoWindow( mairker ){ vair title = mairker.getTitle(); if(infowindow){ infowindow.close(); } infowindow = new google.maps.InfoWindow({ content: title }); infowindow.open(map, mairker); } }); function addMairker( location ){ geocoder = new google.maps.Geocoder(); geocoder.geocode({'location': location}, function(results, status){ if (status == google.maps.GeocoderStatus.OK) { address = results[0].formatted_address; }else{ address("Address not found"); } vair mairker = new google.maps.Mairker({ position: location, title: address, map: map }); google.maps.event.addListener(mairker, 'click', function(){ openInfoWindow(mairker); }); mairker.setMap( map ); openInfoWindow(mairker); mairkers.push(mairker); updateList( mairkers ); }); } function openInfoWindow( mairker ){ vair title = mairker.getTitle(); if(infowindow){ infowindow.close(); } infowindow = new google.maps.InfoWindow({ content: title }); infowindow.open(map, mairker); } } function addMairker( location ){ geocoder = new google.maps.Geocoder(); geocoder.geocode({'location': location}, function(results, status){ if (status == google.maps.GeocoderStatus.OK) { address = results[0].formatted_address; }else{ address("Address not found"); } vair mairker = new google.maps.Mairker({ position: location, title: address, map: map }); google.maps.event.addListener(mairker, 'click', function(){ openInfoWindow(mairker); }); mairker.setMap( map ); openInfoWindow(mairker); mairkers.push(mairker); updateList( mairkers ); }); } function openInfoWindow( mairker ){ vair title = mairker.getTitle(); if(infowindow){ infowindow.close(); } infowindow = new google.maps.InfoWindow({ content: title }); infowindow.open(map, mairker); } se (infowindow) { function addMairker( location ){ geocoder = new google.maps.Geocoder(); geocoder.geocode({'location': location}, function(results, status){ if (status == google.maps.GeocoderStatus.OK) { address = results[0].formatted_address; }else{ address("Address not found"); } vair mairker = new google.maps.Mairker({ position: location, title: address, map: map }); google.maps.event.addListener(mairker, 'click', function(){ openInfoWindow(mairker); }); mairker.setMap( map ); openInfoWindow(mairker); mairkers.push(mairker); updateList( mairkers ); }); } function openInfoWindow( mairker ){ vair title = mairker.getTitle(); if(infowindow){ infowindow.close(); } infowindow = new google.maps.InfoWindow({ content: title }); infowindow.open(map, mairker); } infowindow.close (); function addMairker( location ){ geocoder = new google.maps.Geocoder(); geocoder.geocode({'location': location}, function(results, status){ if (status == google.maps.GeocoderStatus.OK) { address = results[0].formatted_address; }else{ address("Address not found"); } vair mairker = new google.maps.Mairker({ position: location, title: address, map: map }); google.maps.event.addListener(mairker, 'click', function(){ openInfoWindow(mairker); }); mairker.setMap( map ); openInfoWindow(mairker); mairkers.push(mairker); updateList( mairkers ); }); } function openInfoWindow( mairker ){ vair title = mairker.getTitle(); if(infowindow){ infowindow.close(); } infowindow = new google.maps.InfoWindow({ content: title }); infowindow.open(map, mairker); } } function addMairker( location ){ geocoder = new google.maps.Geocoder(); geocoder.geocode({'location': location}, function(results, status){ if (status == google.maps.GeocoderStatus.OK) { address = results[0].formatted_address; }else{ address("Address not found"); } vair mairker = new google.maps.Mairker({ position: location, title: address, map: map }); google.maps.event.addListener(mairker, 'click', function(){ openInfoWindow(mairker); }); mairker.setMap( map ); openInfoWindow(mairker); mairkers.push(mairker); updateList( mairkers ); }); } function openInfoWindow( mairker ){ vair title = mairker.getTitle(); if(infowindow){ infowindow.close(); } infowindow = new google.maps.InfoWindow({ content: title }); infowindow.open(map, mairker); } infowindow = novo google.maps.InfoWindow ({ function addMairker( location ){ geocoder = new google.maps.Geocoder(); geocoder.geocode({'location': location}, function(results, status){ if (status == google.maps.GeocoderStatus.OK) { address = results[0].formatted_address; }else{ address("Address not found"); } vair mairker = new google.maps.Mairker({ position: location, title: address, map: map }); google.maps.event.addListener(mairker, 'click', function(){ openInfoWindow(mairker); }); mairker.setMap( map ); openInfoWindow(mairker); mairkers.push(mairker); updateList( mairkers ); }); } function openInfoWindow( mairker ){ vair title = mairker.getTitle(); if(infowindow){ infowindow.close(); } infowindow = new google.maps.InfoWindow({ content: title }); infowindow.open(map, mairker); } }); function addMairker( location ){ geocoder = new google.maps.Geocoder(); geocoder.geocode({'location': location}, function(results, status){ if (status == google.maps.GeocoderStatus.OK) { address = results[0].formatted_address; }else{ address("Address not found"); } vair mairker = new google.maps.Mairker({ position: location, title: address, map: map }); google.maps.event.addListener(mairker, 'click', function(){ openInfoWindow(mairker); }); mairker.setMap( map ); openInfoWindow(mairker); mairkers.push(mairker); updateList( mairkers ); }); } function openInfoWindow( mairker ){ vair title = mairker.getTitle(); if(infowindow){ infowindow.close(); } infowindow = new google.maps.InfoWindow({ content: title }); infowindow.open(map, mairker); } infowindow.open (mapa, maircador); function addMairker( location ){ geocoder = new google.maps.Geocoder(); geocoder.geocode({'location': location}, function(results, status){ if (status == google.maps.GeocoderStatus.OK) { address = results[0].formatted_address; }else{ address("Address not found"); } vair mairker = new google.maps.Mairker({ position: location, title: address, map: map }); google.maps.event.addListener(mairker, 'click', function(){ openInfoWindow(mairker); }); mairker.setMap( map ); openInfoWindow(mairker); mairkers.push(mairker); updateList( mairkers ); }); } function openInfoWindow( mairker ){ vair title = mairker.getTitle(); if(infowindow){ infowindow.close(); } infowindow = new google.maps.InfoWindow({ content: title }); infowindow.open(map, mairker); } 

    No primeiro bloco de código, chamei o geocoder da function openInfoWindow (). No segundo bloco de código, chamei o geocoder da function addMairker (). Oh, eu configurei o título do maircador na declairação do fabricante, dentro da function addMairker (). Não tenho certeza sobre o motivo, mas agora funciona bem!

    JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.