GeolocateControl class
A GeolocateControl
control provides a button that uses the browser's geolocation
API to locate the user on the map.
Not all browsers support geolocation, and some users may disable the feature. Geolocation support for modern browsers including Chrome requires sites to be served over HTTPS. If geolocation support is not available, the GeolocateControl will not be visible.
The zoom level applied will depend on the accuracy of the geolocation provided by the device.
The GeolocateControl 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 states:
- active - the map's camera automatically updates as the user's location changes, keeping the location dot in the center.
- passive - the user's location dot automatically updates, but the map's camera does not.
- disabled
@implements {IControl}
@param {Object} options
@param {Object} options.positionOptions={enableHighAccuracy: false, timeout: 6000}
A Geolocation API PositionOptions object.
@param {Object} options.fitBoundsOptions={maxZoom: 15}
A fitBounds
options object to use when the map is panned and zoomed to the user's location. The default is to use a maxZoom
of 15 to limit how far the map will zoom in for very accurate locations.
@param {Object} options.trackUserLocation=false
If true
the Geolocate Control becomes a toggle button and when active the map will receive updates to the user's location as it changes.
@param {Object} options.showUserLocation=true
By default a dot will be shown on the map at the user's location. Set to false
to disable.
@example map.addControl(new mapboxgl.GeolocateControl({ positionOptions: { enableHighAccuracy: true }, trackUserLocation: true })); @see Locate the user
Constructors
- GeolocateControl(GeolocateControlOptions options)
-
factory
- GeolocateControl.fromJsObject(GeolocateControlJsImpl jsObject)
-
Creates a new Camera from a
jsObject
.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- jsObject → GeolocateControlJsImpl
-
JS object.
final
- options → GeolocateControlOptions
-
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
fire(
Event event, [dynamic properties]) → dynamic -
inherited
-
listens(
String type) → dynamic -
Returns a true if this instance of Evented or any forwardeed instances of Evented have a listener for the specified type.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
off(
String type, [dynamic layerIdOrListener, Listener? listener]) → MapboxMap -
Removes a previously registered event listener.
inherited
-
on(
String type, [dynamic layerIdOrListener, Listener? listener]) → MapboxMap -
Adds a listener to a specified event type.
inherited
-
onAdd(
MapboxMap map) → dynamic -
once(
String type, Listener listener) → MapboxMap -
Adds a listener that will be called only once to a specified event type.
inherited
-
onRemove(
MapboxMap map) → dynamic -
setEventedParent(
[Evented? parent, dynamic data]) → dynamic -
Bubble all events fired by this instance of Evented to this parent instance of Evented.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
trigger(
) → dynamic - Trigger a geolocation
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited