Maps SDK for Web
Class L.Location
Shows a button that provides location capabilities.
Constructor
L.Location([options])
Parameters
Name | Description | Required | Type/Values | Default |
---|---|---|---|---|
options | No | Object | None | |
options.imageSrc | The image path for locate button. If this option is passed the button would
be created as an <img> tag.
|
No | String | null |
options.size | Its an array of two integers (width, height). The default size of the icon will be double if the user's device has a screen with Retina display capability. Allows to change size of the image, a useful option for SVG images. | No | Number[] | [34,34] |
options.className | The class name of the container element. With this option an external icon library (i.e. Font Awesome) could be used for widget's button. | No | String | "" |
Example
var widget = (new L.Location()).addTo(map);
widget.on(L.Location.Events.LocationFound, function (event) {
console.log('LocationFound');
console.log(event);
});
widget.on(L.Location.Events.LocationError, function (event) {
console.log('LocationError');
console.log(event);
});
Methods
onAdd(map): HTMLElement
The method to instantiates the location control. Executed when adding to map.
Parameters
Name | Description | Required | Type/Values | Default |
---|---|---|---|---|
map | Leaflet map to add control to. | Yes | Object | None |
Returns
Events
All the class events are keys of the Events static member.
To learn more about how to listen events please refer to this documentation.
LocationError
Event that is fired when obtaining user's current location fails.
Properties
Name | Description | Type/Values | Default |
---|---|---|---|
eventObject | All failure information | Object | None |
type | Event's name | String | "locationError" |
target | Event's target | Element | None |
Example
var widget = (new L.Location()).addTo(map);
widget.on(L.Location.Events.LocationError, function (eventObject) {
console.log(eventObject);
});
LocationFound
Event that is fired when obtaining user's current location succeed.
Properties
Name | Description | Type/Values | Default |
---|---|---|---|
eventObject | The found location details | Object | None |
type | Event's name | String | "locationFound" |
target | Event's target | Element | None |
Example
var widget = (new L.Location()).addTo(map);
widget.on(L.Location.Events.LocationFound, function (eventObject) {
console.log(eventObject);
});