IT Study/Web
[HTML] 경도,위도 구하기
도뿌리
2018. 8. 6. 13:58
navigater활용
(navigator.geolocation.getCurrentPosition)
경도 : (파라미터명).coords.latitude
위도 : (파라미터명).coords.longitude
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> geolocation : 위도, 경도 <p id="demo">버튼을 클릭하면 당신의 위치를 출력합니다.</p> <button onclick="getLocation()">클릭</button> <script type="text/javascript"> //x를 demo랑 연결 var x = document.getElementById("demo"); function getLocation() { //alert("getLocation"); if(navigator.geolocation){ navigator.geolocation.getCurrentPosition(showPosition); } else{ alert("위치를 얻을 수 없습니다."); } } function showPosition(position) { x.innerHTML = "위도:" + position.coords.latitude + " 경도:" + position.coords.longitude; } </script> </body> </html> | cs |