- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title></title>
- </head>
- <body>
- <p id="demo">点击这个按钮,获得您的坐标:</p>
- <button onclick="getLocation()">试一下</button>
- <script>
- var x=document.getElementById("demo");
- function getLocation()
- {
- if (navigator.geolocation)
- {
- navigator.geolocation.watchPosition(showPosition);
- }
- else{x.innerHTML="Geolocation is not supported by this browser.";}
- }
- function showPosition(position)
- {
- x.innerHTML="Latitude: " + position.coords.latitude +
- "<br />Longitude: " + position.coords.longitude;
- }
- </script>
- </body>
- </html>
转载请注明:苏demo的别样人生 » h5 通过网页授权获取用户地理位置信息