control.GeolocationControl

Extends control.Button.

The "geolocation" control. Allows you to render the user's position on the map. The key of the control in the storage. control.storage — "geolocationControl".

See geolocation

Constructor | Fields | Events | Methods

Constructor

control.GeolocationControl([parameters])

Parameters:

Parameter

Default value

Description

parameters

Type: Object

Control parameters.

parameters.data

Type: Object

Object describing the data of a control.

parameters.data.image

'geolocation'

Type: String

URL of the button icon.

parameters.data.title

Type: String

Text of the popup hint that appears when the mouse cursor hovers over the button.

parameters.options

Type: Object

Control options.

parameters.options.adjustMapMargin

false

Type: Boolean

Whether the control registers its size in the map margins manager map.margin.Manager.

parameters.options.float

"right"

Type: String

The side to which you want to align the control. Can take three values: "left", "right" or "none". If set to "left" or "right", the controls are arranged one by one, starting from the left or right edge of the map, respectively. If set to "none", the controls are positioned according to the values of the left, right, bottom and top options, relative to the boundaries of the map. See also the description of the position option.

parameters.options.floatIndex

300

Type: Number

The priority of the control positioning. The element with highest priority is positioned closer to the map boundary that is specified in the float property. Does not work with float = "none".

parameters.options.maxWidth

28

Type: Number|Number[]

The maximum width of the control in different states. If a number is specified, it is assumed that the control has the same maximum dimensions in all states. If an array is specified, it will be interpreted as the maximum width in different states from the lesser to the greater. The number of states is set in the instance of the class control.Manager, which is usually a field of Map.controls, via the "states" option. By default, the control does not change its size and always looks like a button with an icon.

parameters.options.noPlacemark

false

Type: Boolean

When set to true, the location marker is not shown on the map, and automatic shifting of the map center and scaling does not occur.

parameters.options.position

Type: Object

Object describing the position of a control. If the position option is set, the float option value is automatically treated as "none".

parameters.options.position.bottom

'auto'

Type: Number|String

Position relative to the bottom edge of the map.

parameters.options.position.left

'auto'

Type: Number|String

Position relative to the left edge of the map.

parameters.options.position.right

'auto'

Type: Number|String

Position relative to the right edge of the map.

parameters.options.position.top

'auto'

Type: Number|String

Position relative to the top edge of the map.

parameters.options.visible

true

Type: Boolean

Indicates if the control is displayed.

parameters.state

Type: Object

Object describing the state of a control.

options.useMapMargin

true

Type: Boolean

Whether to account for map margins map.margin.Manager when centering the map.

Example:

// Adding the control with a custom geolocation placemark on the map.
var geolocationControl = new ymaps.control.GeolocationControl({
    options: {noPlacemark: true}
});
geolocationControl.events.add('locationchange', function (event) {
    var position = event.get('position');
    // When creating a placemark, you can set any appearance for it.
    var locationPlacemark = new ymaps.Placemark(position);

    myMap.geoObjects.add(locationPlacemark);
    // Setting the new map center to the user's current location.
    myMap.panTo(position);
});
myMap.controls.add(geolocationControl);

Fields

Name

Type

Description

data

data.Manager

Button data. Names of fields that are available via the data.Manager.get method:

  • image - Button icon, if available.
  • content - Button content in HTML format.
  • title - Text of the popup hint that appears when the mouse cursor hovers over the button.

Inherited from control.Button.

events

IEventManager

Event manager.

Inherited from IEventEmitter.

options

IOptionManager

Options manager.

Inherited from IControl.

press

The event indicating that the button has been pressed. Unlike the click event, it is generated only if the state isEnabled == true. Instance of the Event class.

Inherited from control.Button.

state

data.Manager

Button state. Names of fields that are available via the data.Manager.get method:

  • selected - Indicates whether the button is selected.
  • enabled - Indicates whether the button is active.
  • size - The size that is currently set for the button.

Inherited from control.Button.

Events

Name

Description

click

Clicking the button. Instance of the Event class.

Inherited from control.Button.

deselect

The control is not selected.

Inherited from ISelectableControl.

disable

The control is unavailable.

Inherited from ISelectableControl.

enable

The control is available.

Inherited from ISelectableControl.

locationchange

The event of determining the user's position. The list of event fields that are available via the Event.get:

  • position - The user's position, in geo coordinates.
  • geoObjects — An instance of the GeoObjectCollection class with the object that represents the user's current location.

optionschange

Change to the object options.

Inherited from ICustomizable.

parentchange

The parent object reference changed.

Data fields:

  • oldParent - Old parent.
  • newParent - New parent.

Inherited from IChild.

select

The control is selected.

Inherited from ISelectableControl.

Methods

Name

Returns

Description

deselect()

Cancels selection of the control (turns it off).

Inherited from ISelectableControl.

disable()

Makes the control unavailable (user actions are not allowed).

Inherited from ISelectableControl.

enable()

Makes the control available (user actions are allowed).

Inherited from ISelectableControl.

getMap()

Map

Returns reference to the map.

Inherited from control.Button.

getParent()

IControlParent|null

Returns link to the parent object, or null if the parent element was not set.

Inherited from IControl.

isEnabled()

Boolean

Returns true if the control is available, or false if it is unavailable.

Inherited from ISelectableControl.

isSelected()

Boolean

Returns true if the control is selected, or false if it is not selected.

Inherited from ISelectableControl.

select()

Selects (turns on) the control.

Inherited from ISelectableControl.

setParent(parent)

IChildOnMap

Sets the parent object. If the null value is passed, the manager element will only be deleted from the current parent object.

Inherited from IControl.

Events details

locationchange

The event of determining the user's position. The list of event fields that are available via the Event.get:

  • position - The user's position, in geo coordinates.
  • geoObjects — An instance of the GeoObjectCollection class with the object that represents the user's current location.