Summary
The nsIDOMGeoGeolocation interface provides access to geolocation information. You can request a single notification of the user's current position, or you can monitor the position over time.
Inherits from: nsISupports
Implemented by: @mozilla.org/geolocation;1. Starting in Gecko 1.9.2, you can access this service using:
var geolocation = Components.classes["@mozilla.org/geolocation;1"]
.getService(Components.interfaces.nsIDOMGeoGeolocation);
Note: if nsIDGeoGeolocation throws an exception when importing, try using this:
var geolocation = Components.classes["@mozilla.org/geolocation;1"]
.getService(Components.interfaces.nsISupports);
Method Overview
void clearWatch(in unsigned short watchId); |
void getCurrentPosition(in nsIDOMGeoPositionCallback successCallback, [optional] in nsIDOMGeoPositionOptions options); |
unsigned short watchPosition(in nsIDOMGeoPositionCallback successCallback, [optional] in nsIDOMGeoPositionOptions options); |
Attributes
| Attribute | Type | Description |
lastPosition |
nsIDOMGeoPosition |
The most recently retrieved location as seen by the provider. May be null. Read only. |
Methods
clearWatch()
When the clearWatch() method is called, the watch() process stops calling for new position identifiers and cease invoking callbacks.
void clearWatch( in unsigned short watchId );
Parameters
None.
getCurrentPosition()
Acquires the user's current position via a new position object. If this fails, errorCallback is invoked with an nsIDOMGeoPositionError argument.
void getCurrentPosition( in nsIDOMGeoPositionCallback successCallback, [optional] in nsIDOMGeoPositionErrorCallback errorCallback, [optional] in nsIDOMGeoPositionOptions options );
Parameters
-
successCallback -
An
nsIDOMGeoPositionCallbackto be called when the current position is available.
-
errorCallback -
An
nsIDOMGeoPositionErrorCallbackthat is called if an error occurs while retrieving the position; this parameter is optional.
-
options -
An
nsIDOMGeoPositionOptionsobject specifying options; this parameter is optional.
watchPosition()
Similar to getCurrentPosition(), except it continues to call the callback with updated position information periodically until clearWatch() is called.
unsigned short watchPosition( in nsIDOMGeoPositionCallback successCallback, [optional] in nsIDOMGeoPositionErrorCallback errorCallback, [optional] in nsIDOMGeoPositionOptions options );
Parameters
-
successCallback -
An
nsIDOMGeoPositionCallbackthat is to be called whenever new position information is available.
-
errorCallback -
An
nsIDOMGeoPositionErrorCallbackto call when an error occurs; this is an optional parameter.
-
options -
An
nsIDOMGeoPositionOptionsobject specifying options; this parameter is optional.
Return value
An ID number that can be used to reference the watcher in the future when calling clearWatch().
