Home › Forums › Front-end Issues › Google Maps Field: Zooming in when address is found? › Reply To: Google Maps Field: Zooming in when address is found?
Hi @dtx211
I think you can use the google_map_change
JavaScript action and check if the location is changed or not. It should be something like this:
// change map zoom on map change
add_action('acf/input/admin_footer', 'my_acf_change_zoom');
function my_acf_change_zoom() {
?>
<script type="text/javascript">
(function($) {
// do this when the map is changed
acf.add_action('google_map_change', function( latlng, $map, $field ){
// check if the new location is different from the pre-defined location
if( latlng.lat() != -37.81411 ||
latlng.lng() != 144.96328 ){
// zoom the map if it's differrent
$map.setZoom(14);
}
});
})(jQuery);
</script>
<?php
}
Don’t forget to change the pre-defined location (-37.81411, 144.96328).
I hope this helps 🙂
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.