본문 바로가기

IT Study/Web

[HTML] 경도,위도 구하기

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


'IT Study > Web' 카테고리의 다른 글

[JavaScript] JavaScript 사진 변환 기본 예제  (0) 2018.08.06
[HTML] 영상(video) 출력  (0) 2018.08.06
[HTML] form 기본 예제  (0) 2018.08.06
[HTML] iframe  (0) 2018.08.06
[HTML] CSS 적용방법 3가지  (0) 2018.08.06