Class

PositionControl

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).

Constructor

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.
Parameters:
Name Type Description
element HTMLElement An element to hold the position control that should be added to the map
options PositionControlOptions
Example
// 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
myGoogleMap.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(myPositionControlElm);

Members

GeolocationPosition

currentPosition

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

positionState

The current state of device positioning. One of PositionState.

Methods

hasValidPosition() → {Boloean}

Returns if position is known and accurate
Boloean

panToCurrentPosition()

Pan map to center on the current position.
Example
// Create position control and always follow current position
const myPositionControlElm = document.createElement('div');
const myPositionControl = new mapsindoors.PositionControl(myPositionControlElm, { mapsIndoors: myMapsIndoors, maxAccuracy: 125 });
myGoogleMap.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(myPositionControlElm);
google.maps.event.addListener(myMapsindoors, 'position_received', position => {
    myPositionControl.panToCurrentPosition();
});

watchPosition(selfInvokedopt)

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

Events

position_error

Position error event. Fired in case of a positioning error.

object

Properties:
Name Type Description
code Number 1-3: GeolocationError code. 10: Geolocation not available. 11: Inaccurate position
message string Error message
Example
google.maps.event.addListener(myMapsindoors, 'position_error', reason => {
    // Do something with error reason { code: <number>, message: <string> }
});

position_received

Position received event. Fired whenever position is retreived or updated.

Object

Properties:
Name Type Description
selfInvoked Boolean If the position request was invoked by clicking on the position control.
accurate Boolean If the position is accurate (below the maxAccuracy set in options)
position GeolocationPosition GeolocationPosition
Example
google.maps.event.addListener(myMapsindoors, 'position_received', payload => {
    // Do something with eg. payload.position
});