Navigator.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.

Navigator.geolocation 回傳一個唯讀的 Geolocation 物件,透過這個物件可以存取設備的位置訊息。同時也允許網站或應用程式根據使用者的位置提供客製化的結果。

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

語法

geo = navigator.geolocation

規格

Specification
Geolocation
# dom-navigator-geolocation

瀏覽器相容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
geolocation
Secure context required

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

請參考