Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

nsIDOMGeoGeolocation

This article needs a technical review. How you can help.

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.

Please add a summary to this article.
  Last changed in Gecko 1.9.1 (Firefox 3.5 / Thunderbird 3.0 / SeaMonkey 2.0)

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 nsIDOMGeoPositionErrorCallback errorCallback,

                       [optional] in nsIDOMGeoPositionOptions options);
unsigned short watchPosition(in nsIDOMGeoPositionCallback successCallback,
                             [optional] in nsIDOMGeoPositionErrorCallback errorCallback,

                             [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 nsIDOMGeoPositionCallback to be called when the current position is available.
errorCallback
An nsIDOMGeoPositionErrorCallback that is called if an error occurs while retrieving the position; this parameter is optional.
options
An nsIDOMGeoPositionOptions object 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 nsIDOMGeoPositionCallback that is to be called whenever new position information is available.
errorCallback
An nsIDOMGeoPositionErrorCallback to call when an error occurs; this is an optional parameter.
options
An nsIDOMGeoPositionOptions object 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().

Document Tags and Contributors

 Contributors to this page: fscholz, Sheppy, ScottGoci, Steffen, Wjjohnst, fiveinchpixie
 Last updated by: fscholz,