Support

Account

Home Forums Front-end Issues Google Map infoWindow.close() Reply To: Google Map infoWindow.close()

  • Hi @vespino

    ACF can only return the latitude, longitude and the address data of your Google map field. What you want to do with those data is up to you. You don’t have to follow the example code provided by ACF. For example, by following the source code of the page you shared, you can generate Javascript code that will do what you want like this:

    ...
    ...
        google.maps.event.addListener(map, 'click', function() {
          infoWindow.close();
        });
    
    		<?php if( have_rows('locations') ): ?>
    			<?php $i = 1; ?>
    			<?php while ( have_rows('locations') ) : the_row();
    				$location = get_sub_field('location');
    				?>
    				var marker<?php echo $i; ?> = new google.maps.Marker({
    		      map: map,
    		      position: new google.maps.LatLng(<?php echo $location['lat']; ?>, <?php echo $location['lng']; ?>)
    		    });
    				google.maps.event.addListener(marker<?php echo $i; ?>, 'click', onMarkerClick);
    				<?php $i++; ?>
    			<?php endwhile; ?>
    		<?php endif; ?>
      });
    </script>
    ...
    ...

    I hope this makes sense.