사용자의 위치를 표시하는 간단한 HTML 코드를 제공합니다. 이 코드는 사용자의 현재 위치 정보를 가져와 표시합니다. 주석을 통해 코드를 설명하였습니다.
<!DOCTYPE html>
<html>
<head>
<title>사용자 위치 표시</title>
</head>
<body>
<h1>사용자 위치</h1>
<!-- 위치 표시 영역 -->
<p>현재 위치: <span id="location">위치 정보를 불러오는 중...</span></p>
<script>
// 사용자 위치를 가져와 표시하는 함수
function showLocation() {
// 위치 정보를 가져오기
if ("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition(function(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var locationElement = document.getElementById("location");
locationElement.textContent = "위도: " + latitude + ", 경도: " + longitude;
});
} else {
var locationElement = document.getElementById("location");
locationElement.textContent = "위치 정보를 사용할 수 없습니다.";
}
}
// 페이지 로드 시 위치 정보 표시
window.onload = showLocation;
</script>
</body>
</html>
'HTML 예제' 카테고리의 다른 글
날짜 및 시간 표시 (0) | 2023.12.07 |
---|---|
다크 모드 토글 (0) | 2023.12.07 |
동적으로 목록 추가 (0) | 2023.12.07 |
화면 알림 뛰우기 (0) | 2023.12.07 |
간단한 로그인 폼 (0) | 2023.12.07 |