Showing
2 changed files
with
31 additions
and
0 deletions
gps_api/example.html
0 → 100644
1 | +<!DOCTYPE html> | ||
2 | +<html lang="ko"> | ||
3 | + | ||
4 | +<head> | ||
5 | + <meta charset="UTF-8"> | ||
6 | + <meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
7 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
8 | + <title>Geolocation example - getCurrentPosition()</title> | ||
9 | +</head> | ||
10 | + | ||
11 | +<body> | ||
12 | +<script type="text/javascript" src="practice.js"></script> | ||
13 | +</body> | ||
14 | + | ||
15 | +</html> |
gps_api/practice.js
0 → 100644
1 | +if (navigator.geolocation) { | ||
2 | + navigator.geolocation.getCurrentPosition(success, error); | ||
3 | + } else { | ||
4 | + alert("Your browser is not support geolocation.")//navigator이 현재 브라우저에서 작동하지 않는 경우 | ||
5 | + } | ||
6 | + | ||
7 | + function success(position) { | ||
8 | + var latitude = position.coords.latitude; | ||
9 | + var longitude = position.coords.longitude | ||
10 | + console.log(`Your latitude is ${latitude} and your longitude is ${longitude}`) // 위도와 경도 값을 console로 알려줌 | ||
11 | + return (latitude, longitude); | ||
12 | + } | ||
13 | + | ||
14 | + function error() { | ||
15 | + alert("Can't detect your location. Try again later.") // error function | ||
16 | + } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment