Geolocation
介面代表一個物件可以透過你的網頁程式去獲得你的裝置位置。這個介面提供了網站或應用程式根據使用者的位置去客製化呈現的內容。
Navigator
此物件實作了 Navigator.geolocation
介面。
備註: 因為隱私的因素,當網頁要求存取位置資訊時,用戶會被提示通知並且詢問授權與否。注意不同的瀏覽器在詢問授權時有各自不同的策略和方式。
性質
Geolocation
介面沒有繼承也沒有時做任何方法。
方法
Geolocation
介面沒有繼承任何方法。
Geolocation.getCurrentPosition()
- 取得裝置當前位置,並回傳
Position
。 Geolocation.watchPosition()
- 返回一個長整數,註冊一個回呼函數。這個方法是用來註冊一個處理的函式,當使用者的裝置位置更新時,這個函式所傳入的回呼函式(callback function) 就會自動被呼叫。
Geolocation.clearWatch()
- 移除指定註冊的
watchPosition()
。
規格
Specification | Status | Comment |
---|---|---|
Geolocation API | Recommendation | Initial specification. |
瀏覽器相容性
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 5 | 3.5 (1.9.1) | 9 | 10.60 Removed in 15.0 Reintroduced in 16.0 |
5 |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | ? | ? | 4.0 (4) | ? | 10.60 | ? |