Get Current Location using addGeolocateControls
This documentation provides methods for getting, tracking users current location using addGeolocateControls
This provides a button that uses the browser's geolocation API to locate the user on the map.
This has two modes. If trackUserLocation is false (default) the control acts as a button, which when pressed will set the map's camera to target the user location. If the user moves, the map won't update. This is most suited for the desktop. If trackUserLocation is true the control acts as a toggle button that when active the user's location is actively monitored for changes. In this mode the GeolocateControl has three interaction states: * active - the map's camera automatically updates as the user's location changes, keeping the location dot in the center. Initial state and upon clicking the GeolocateControl button. * passive - the user's location dot automatically updates, but the map's camera does not. Occurs upon the user initiating a map movement. * disabled - occurs if Geolocation is not available, disabled or denied.
Example
Use addGeolocateControls to set users location
Programmatically request and move the map to the user's location.
Events
geolocate
This event is triggered when the user's location is successfully retrieved.
error
This event is emitted when there is an error in retrieving the user's location.
trackuserlocationstart
Triggered when tracking of the user's location begins.
trackuserlocationend
Triggered when tracking of the user's location ends.
userlocationfocus
Triggered when the user's location gains focus, such as when a map is centered on it.
userlocationlostfocus
Triggered when the user's location loses focus, such as when the map is panned away.
outofmaxbounds
Triggered when the user's location is outside the defined maximum bounds.