nsIDOMGeoGeolocation 编辑

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.

dom/interfaces/geolocation/nsIDOMGeoGeolocation.idlScriptable 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

AttributeTypeDescription
lastPositionnsIDOMGeoPositionThe 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().

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:84 次

字数:7723

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文