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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.