js手機獲取當前經緯度
阿新 • • 發佈:2017-11-11
pre 獲取 location spa 點擊 var type 坐標 coo
<!DOCTYPE html> <html> <head> </head> <body> <p id="demo">點擊這個按鈕,獲得您的坐標:</p> <button onclick="getLocation()">試一下</button> <script> var x=document.getElementById("demo"); function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(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>
該方法必須在手機上測試才有有效
js手機獲取當前經緯度