Change default map zoom on contact page

please help to change the default zoom level, its way too zoomed out by default, thanks

Hello there,

Firstly you’ve to add this PHP function to your child theme’s functions.php file. Or you can use a functionality plugin like Code Snippets (ensure the code runs in the front end).

    add_action( 'wp_enqueue_scripts', 'perth_pro_child_contact_map', 9999 );
    function perth_pro_child_contact_map() {

      if( !is_page_template('page-templates/page_contact.php') ) {
        return;
      }

      global $post;

      $contact = array(
        'address' => get_post_meta( $post->ID, '_perth_map_address', true )
      );

      wp_localize_script( 'perth-scripts', 'contact', $contact );

    }

Then do these steps:

  1. Install and activate the TC Custom JavaScript plugin
  2. Go To Appearance > Custom JavaScript
  3. Paste the following code into the provided box
    jQuery(function($) {

      if( $('body').hasClass('page-template-page_contact') && contact.address != '' ) {

        if ( $().gmap3 ) {
            $("#map").gmap3({
                map:{
                    options:{
                        zoom: 17,
                        mapTypeId: 'Idea_style',
                        mapTypeControlOptions: {
                            mapTypeIds: ['Idea_style', google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.HYBRID]
                        },
                        scrollwheel: false
                    }
                },
                getlatlng:{
                    address: contact.address,
                    callback: function(results) {
                        if ( !results ) return;
                        $(this).gmap3('get').setCenter(new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng()));
                        $(this).gmap3({
                            marker:{
                                latLng:results[0].geometry.location
                            }
                        });
                    }
                },
                styledmaptype:{
                    id: "Idea_style",
                    options:{
                        name: "Map"
                    },
                },
            });
        }

      }

    });

The zoom number level is defined in this line:

zoom: 17,

The default value is 14

4 . Update

Clear site cache (if applied) as it usually block the new code addition from immediate effect.

https://codex.wordpress.org/I_Make_Changes_and_Nothing_Happens

Regards,
Kharis