Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding an external "find my location" button outside of the map

I'm trying to add a button above my map that would show the current location of the user.

Basically i want to duplicate the functionality of the built in button but make a more obvious one.

Here's my code:

<script>
  var map = L.mapbox.map('map', 'plisvb.hopljoko');
  L.control.locate({
    drawCircle: true, // controls whether a circle is drawn that shows the uncertainty about the location
    setView: true, // automatically sets the map view to the user's location, enabled if `follow` is true
    keepCurrentZoomLevel: false, // keep the current map zoom level when displaying the user's location. (if `false`, use maxZoom)
    icon: 'icon-location', // `icon-locate` or `icon-direction`
    iconLoading: 'icon-spinner  animate-spin', // class for loading icon
    circlePadding: [0, 0], // padding around accuracy circle, value is passed to setBounds
    locateOptions: {
      maxZoom: 15
    },
    strings: {
      title: "Click to see your current location", // title of the locate control
      popup: "Your current location", // text to appear if user clicks on circle
      outsideMapBoundsMsg: "You seem located outside the boundaries of the map" // default message for onLocationOutsideMapBounds
    }
  }).addTo(map);
  map.scrollWheelZoom.disable();
</script>

any ideas?

like image 230
user127181 Avatar asked Nov 22 '25 12:11

user127181


1 Answers

The question was posted a year ago but if people are still looking for an answer I found the following: http://codepen.io/leemark/pen/vcbuf

$('.pure-button').on('click', function(){
mymap.locate({setView: true, maxZoom: 15});
});

In the example provided this is the call on the click event of the button. You can either use their button or create a different looking one.

I'm not sure if it is exactly what I want and not sure if I will implement it. However it seem to answer the original post.

like image 87
user1527152 Avatar answered Nov 24 '25 06:11

user1527152



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!