Title: Geolocation
Last modified: April 20, 2022

---

# Geolocation

 *  Resolved [Killian Santos](https://wordpress.org/support/users/killiansantos/)
 * (@killiansantos)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/geolocation-34/)
 * Hello,
    I would like to add the following plugin [https://github.com/domoritz/leaflet-locatecontrol](https://github.com/domoritz/leaflet-locatecontrol)
   to allow users to be geolocated on the map.
 * I tried to start from the FAQ which would give something like this?
 * **functions.php**
 *     ```
       add_action('leaflet_map_loaded', 'fs_leaflet_loaded');
       function fs_leaflet_loaded() {
         wp_enqueue_script('locate_leaflet', 'https://cdn.jsdelivr.net/npm/leaflet.locatecontrol@0.74.0/dist/L.Control.Locate.min.js', Array('wp_leaflet_map'), '1.0', true);
         wp_enqueue_style('locate_leaflet_styles', 'https://cdn.jsdelivr.net/npm/leaflet.locatecontrol@0.74.0/dist/L.Control.Locate.min.css');
       }
       ```
   
 * **on the pages**
 *     ```
       <script>
       L.control.locate({
           strings: {
               title: "Show me where I am, yo!"
           }
       }).addTo(map);
       </script>
       ```
   
 * Am I missing something?
 * Thanks for your help.

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Contributor [hupe13](https://wordpress.org/support/users/hupe13/)
 * (@hupe13)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/geolocation-34/#post-15577599)
 * Yes, some more custom js:
 *     ```
       <script>
       window.WPLeafletMapPlugin = window.WPLeafletMapPlugin || [];
       window.WPLeafletMapPlugin.push(function () {
         var map = window.WPLeafletMapPlugin.getCurrentMap();
         L.control.locate({
           strings: {
             title: "Show me where I am, yo!"
           }
         }).addTo(map);
       });
       </script>
       ```
   
 * (not tested)
    -  This reply was modified 4 years, 1 month ago by [hupe13](https://wordpress.org/support/users/hupe13/).
 *  Thread Starter [Killian Santos](https://wordpress.org/support/users/killiansantos/)
 * (@killiansantos)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/geolocation-34/#post-15577667)
 * Hello [@hupe13](https://wordpress.org/support/users/hupe13/),
 * Thank you for your help.
 * I tried to add the code you kindly suggested. I get the following error in the
   console: “TypeError: L.control.locate is not a function” with the following file
   as reference: /wp-content/plugins/leaflet-map/scripts/construct-leaflet-map.min.
   js?ver=3.0.4
 * Any idea ?
 *  Plugin Contributor [hupe13](https://wordpress.org/support/users/hupe13/)
 * (@hupe13)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/geolocation-34/#post-15577713)
 * Open the Developer Console and look at any errors.
 *  Plugin Contributor [hupe13](https://wordpress.org/support/users/hupe13/)
 * (@hupe13)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/geolocation-34/#post-15579746)
 * I tested it now, it works for me principally, but not perfect. Do you have an
   URL to your testpage?
 *  Thread Starter [Killian Santos](https://wordpress.org/support/users/killiansantos/)
 * (@killiansantos)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/geolocation-34/#post-15579787)
 * Thank you very much for your help [@hupe13](https://wordpress.org/support/users/hupe13/).
   Back in front of my computer, here is a test url: [https://url.dev/ZXtVfSL/](https://url.dev/ZXtVfSL/)
 * The map concerned is the main map (not the small ones).
 *  Thread Starter [Killian Santos](https://wordpress.org/support/users/killiansantos/)
 * (@killiansantos)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/geolocation-34/#post-15579995)
 * I found the source of the problem. By disabling the multiple small cards, the
   button appeared… it works fine.
 * I thank you again for your precious help [@hupe13](https://wordpress.org/support/users/hupe13/)
   🙂
 *  [Arnaud G.](https://wordpress.org/support/users/nonopinspins/)
 * (@nonopinspins)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/geolocation-34/#post-16045188)
 * Hello,
    Sorry to come back to this topic, but I can’t add geolocation to my map.
   Can you explain which codes should be added where please? My skills in this area
   very weak, and I need to be guided. Thanks !
 *  Thread Starter [Killian Santos](https://wordpress.org/support/users/killiansantos/)
 * (@killiansantos)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/geolocation-34/#post-16046369)
 * Hello [@nonopinspins](https://wordpress.org/support/users/nonopinspins/),
 * Simply add this code to the functions.php file of your theme:
 *     ```
       add_action('leaflet_map_loaded', 'fs_leaflet_loaded');
       function fs_leaflet_loaded() {
         wp_enqueue_script('locate_leaflet', 'https://cdn.jsdelivr.net/npm/leaflet.locatecontrol@0.74.0/dist/L.Control.Locate.min.js', Array('wp_leaflet_map'), '1.0', true);
         wp_enqueue_style('locate_leaflet_styles', 'https://cdn.jsdelivr.net/npm/leaflet.locatecontrol@0.74.0/dist/L.Control.Locate.min.css');
       }
       ```
   
 * And this one on the page where you want to load your map under the shortcode [
   leaflet-map] :
 *     ```
       <script>
       window.WPLeafletMapPlugin = window.WPLeafletMapPlugin || [];
       window.WPLeafletMapPlugin.push(function () {
         var map = window.WPLeafletMapPlugin.getCurrentMap();
         L.control.locate({
           strings: {
             title: "Me géolocaliser sur la carte"
           }
         }).addTo(map);
       });
       </script>
       ```
   
 * I hope this helps!
 *  [Arnaud G.](https://wordpress.org/support/users/nonopinspins/)
 * (@nonopinspins)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/geolocation-34/#post-16046620)
 * It works ! Thank very much [@killiansantos](https://wordpress.org/support/users/killiansantos/).

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Geolocation’ is closed to new replies.

 * ![](https://ps.w.org/leaflet-map/assets/icon-256x256.png?rev=1693083)
 * [Leaflet Map](https://wordpress.org/plugins/leaflet-map/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/leaflet-map/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/leaflet-map/)
 * [Active Topics](https://wordpress.org/support/plugin/leaflet-map/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/leaflet-map/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/leaflet-map/reviews/)

 * 9 replies
 * 3 participants
 * Last reply from: [Arnaud G.](https://wordpress.org/support/users/nonopinspins/)
 * Last activity: [3 years, 8 months ago](https://wordpress.org/support/topic/geolocation-34/#post-16046620)
 * Status: resolved