Skip to content
Advertisement

Location me in map from React Leaflet

I want to ask if I use a map from React Leaflet (https://react-leaflet.js.org/) but how do I add a location button to the map? like this an example of the location me button in the image that I gave the red arrow

And pictures in the link:
Example of an arrow Location Me

An example on my map where I want to add location Me

And how to show the location button, where do you save it from my coding?

JavaScript

Advertisement

Answer

If you need to get the exact same result as in your picture you need to use leaflet-easybutton library with font-awesome. Otherwise you can easily build your own icon by extending leaflet control.

Install them:

JavaScript

Import them:

JavaScript

Instantiate L.easy-button using fa-map-marker icon and inside the callback save the position and move the map to the user location.

JavaScript

Here is a demo. When you open it the icon won’t show up cause there is a known issue with svg icons and codesandbox but locally you should not have any issue.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement