Window navigator.geolocation 属性
- Forrige side cookieEnabled
- Næste side javaEnabled()
- Gå tilbage til niveauet over Window Navigator
定义和用法
geolocation
属性返回可用于定位用户位置的 Geolocation 对象。
geolocation
属性是只读的。
geolocation
属性仅在安全上下文 (HTTPS) 中可用。
geolocation
属性仅在用户批准后才可用。
注释:对于具有 GPS 的设备(例如智能手机),地理位置要准确得多。
另请参阅:
实例
获取用户所在位置的经纬度:
hvis (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); } document.getElementById("demo").innerHTML = "Geolocation er ikke understøttet af denne browser."; } function showPosition(position) { document.getElementById("demo").innerHTML = "Breddegrad: " + position.coords.latitude + "Længdegrad: " + position.coords.longitude; }
语法
navigator.geolocation
返回值
类型 | 描述 |
---|---|
对象 | 对 Geolocation 对象的引用。 |
浏览器支持
所有浏览器都支持 navigator.geolocation
:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support | Support |
- Forrige side cookieEnabled
- Næste side javaEnabled()
- Gå tilbage til niveauet over Window Navigator