Click the “Locate me” button automatically on page load

<?php

// To click the "Locate me" button automatically when the page loads, add the following code to your (child) theme’s functions.php. 
// The Proximity facet will be set to the approximate location of the user, using the default radius. See:
// https://facetwp.com/help-center/facets/facet-types/proximity/#accuracy-of-the-locate-me-button

// Note that this will cause a immediate location permission pop-up on page load.
// Some browsers (like IOS Safari) will not store the permission and will ask repeated permission, on every page with a Proximity facet.
// FacetWP has no influence on these permission pop-ups.

// To prevent the short flash of the first map load with all markers (and its Google API call), see the more elaborate version here: 
// https://facetwp.com/help-center/facets/facet-types/proximity/#click-the-locate-me-button-automatically-on-the-first-map-load

add_action( 'facetwp_scripts', function() {
  ?>
  <script>
    window.addEventListener('DOMContentLoaded', function() {
      if ('undefined' !== typeof FWP.hooks) {
        FWP.hooks.addAction('facetwp/loaded', function() {
          if (! FWP.loaded) {
            fUtil('.locate-me').trigger('click');
          }
        });
      }
    });
  </script>
  <?php
}, 1000);