blob: ffe4aeae2f09be7b1c65143d873ee1e2ac947852 (
plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
---
title: Geolocation.getCurrentPosition()
slug: Web/API/Geolocation/getCurrentPosition
tags:
- API
- Geolocation
- Geolocation API
- Method
- Reference
- Secure context
- 위치
- 위치정보
translation_of: Web/API/Geolocation/getCurrentPosition
---
<div>{{securecontext_header}}{{ APIRef("Geolocation API") }}</div>
<p><strong><code>Geolocation.getCurrentPosition()</code></strong> 메서드는 장치의 현재 위치를 가져옵니다.</p>
<h2 id="구문">구문</h2>
<pre class="syntaxbox">navigator.geolocation.getCurrentPosition(<em>success</em>[, <em>error</em>[, [<em>options</em>]])</pre>
<h3 id="매개변수">매개변수</h3>
<dl>
<dt><code>success</code></dt>
<dd>{{domxref("GeolocationPosition")}} 객체를 유일한 매개변수로 받는 콜백 함수.</dd>
<dt><code>error</code> {{optional_inline}}</dt>
<dd>{{domxref("GeolocationPositionError")}} 객체를 유일한 매개변수로 받는 콜백 함수.</dd>
<dt><code>options</code> {{optional_inline}}</dt>
<dd>{{domxref("PositionOptions")}} 객체.</dd>
</dl>
<h2 id="예제">예제</h2>
<pre class="brush: js">var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function success(pos) {
var crd = pos.coords;
console.log('Your current position is:');
console.log('Latitude : ' + crd.latitude);
console.log('Longitude: ' + crd.longitude);
console.log('More or less ' + crd.accuracy + ' meters.');
};
function error(err) {
console.warn('ERROR(' + err.code + '): ' + err.message);
};
navigator.geolocation.getCurrentPosition(success, error, options);
</pre>
<h2 id="명세">명세</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('Geolocation')}}</td>
<td>{{Spec2('Geolocation')}}</td>
<td>Initial specification.</td>
</tr>
</tbody>
</table>
<h2 id="브라우저_호환성">브라우저 호환성</h2>
<p>{{Compat("api.Geolocation.getCurrentPosition")}}</p>
<h2 id="같이_보기">같이 보기</h2>
<ul>
<li><a href="/ko/docs/Web/API/Geolocation_API/Using_the_Geolocation_API">Geolocation API 사용하기</a></li>
<li>{{domxref("Navigator.geolocation")}}</li>
</ul>
|