Support » Plugin: Leaflet Map » Geolocation

  • Resolved killiansantos

    (@killiansantos)


    Hello,
    I would like to add the following plugin 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 6 replies - 1 through 6 (of 6 total)
  • 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 3 months, 2 weeks ago by hupe13.
    Thread Starter killiansantos

    (@killiansantos)

    Hello @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 ?

    Open the Developer Console and look at any errors.

    I tested it now, it works for me principally, but not perfect. Do you have an URL to your testpage?

    Thread Starter killiansantos

    (@killiansantos)

    Thank you very much for your help @hupe13. Back in front of my computer, here is a test url: https://url.dev/ZXtVfSL/

    The map concerned is the main map (not the small ones).

    Thread Starter killiansantos

    (@killiansantos)

    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 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.