Support

Account

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 🙂