Geolocation

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

We'd love to hear more about your role and the company you work for
Please help us by answering a few questions.

Geolocation 介面代表一個物件可以透過你的網頁程式去獲得你的裝置位置。這個介面提供了網站或應用程式根據使用者的位置去客製化呈現的內容。

Navigator 此物件實作了 Navigator.geolocation 介面。

備註: 因為隱私的因素,當網頁要求存取位置資訊時,用戶會被提示通知並且詢問授權與否。注意不同的瀏覽器在詢問授權時有各自不同的策略和方式。

性質

Geolocation 介面沒有繼承也沒有時做任何方法

方法

Geolocation 介面沒有繼承任何方法

Geolocation.getCurrentPosition()

取得裝置當前位置,並回傳Position

Geolocation.watchPosition()

返回一個長整數,註冊一個回呼函數。這個方法是用來註冊一個處理的函式,當使用者的裝置位置更新時,這個函式所傳入的回呼函式(callback function) 就會自動被呼叫。

Geolocation.clearWatch()

移除指定註冊的 watchPosition()

規格

Specification
Geolocation
# geolocation_interface

瀏覽器相容性

請參考