mapsindoors.PositionControl(element, options)

Show user location on map.

The Position Control object will generate a button for different position states.
When first clicked, it will ask the browser for access to current location (Geolocation API).
When granted access, it will show a position dot and position accuracy circle on the map (if it is accurate enough).
When clicking on the button again, it will center again.
Centering on the position can also be done programmatically.
If granted permanent access to location, the position will be shown immediately at any subsequent initializations (NOTE: not in browsers with no support for Permissions API).

# new PositionControl(element, options)

Attach position control to an HTML element that when clicked (or permission already given) will show current position on the map.
Name Type Description
element HTMLElement An element to hold the position control that should be added to the map
options PositionControlOptions
// Create element to hold the position control
const myPositionControlElm = document.createElement('div');
// Create position control and attach it to element
new mapsindoors.PositionControl(myPositionControlElm, { mapsIndoors: myMapsIndoors, maxAccuracy: 125 });
// Add the element now holding position control to your map:
// For Google Maps:
// For Mapbox:
myMapsIndoorsInstance.getMap().addControl({ onAdd: function () { return myPositionControlElm }, onRemove: function () { } });



# currentPosition

The current position of the device if received (GeolocationPosition).

# positionState

The current state of device positioning. One of PositionState.


# hasValidPosition() → {Boloean}

Returns if position is known and accurate

# panToCurrentPosition()

Pan map to center on the current position.
// Create position control and always follow current position
const myPositionControlElm = document.createElement('div');
const myPositionControl = new mapsindoors.PositionControl(myPositionControlElm, { mapsIndoors: myMapsIndoors });
myPositionControl.addListener(myMapsindoors, 'position_received', () => {

# watchPosition(selfInvokedopt)

Request for current position, emit events and show position on map based on result.
Name Type Attributes Default Description
selfInvoked boolean <optional>
false Used to track if call was invoked by clicking on position control or not.