Cannot read property '__e3_' of undefined
The call
geocoder.geocode( { 'address': country }, function(results, status) { ..
is asynchronous, meaning the line
google.maps.event.addListener(marker, 'click', function() {
will be called before the line
marker = new google.maps.Marker({ ..
is called in your ts_newMapMarker
. So marker
does not exist at the point you want to add event listener to it. You have to somehow re-arrange your code, so you add the listener after the marker is initialized, e.g:
function ts_newMapMarker($marker, map){ var marker; var dataCountry = $marker.attr('data-country'); console.log("Country: " + dataCountry); geocoder = new google.maps.Geocoder(); function getCountry(country) { geocoder.geocode( { 'address': country }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); marker = new google.maps.Marker({ map: map, position: results[0].geometry.location, icon : '<?php bloginfo('template_url'); ?>/assets/images/map-marker.png' }); map.markers.push( marker ); getCountry(dataCountry); // if marker contains HTML, add it to an infoWindow if($marker.html()) { // create info window var infowindow = new google.maps.InfoWindow({ content : $marker.html() }); // show info window when marker is clicked google.maps.event.addListener(marker, 'click', function() { console.log("open info window"); infowindow.open( map, marker ); }); } } else { alert("Geocode was not successful for the following reason: " + status); } }); }}
In my case google.maps.event.addListener(marker, 'click', function() {
The marker variable was undefined. And hence the error. Might be useful for someone.