HTML5 Geolocation API를 사용하면 즐겨찾는 웹사이트와 위치를 공유할 수 있습니다. JavaScript는 위도와 경도를 캡처하고 백엔드 웹 서버로 보내어 지역 비즈니스를 찾거나 지도에 위치를 표시하는 것과 같은 멋진 위치 인식 작업을 수행할 수 있습니다.
지리적 위치 API는 전역 탐색기 개체의 새 속성, 즉. 지리적 위치 개체입니다.
getCurrentPosition 메소드는 장치의 현재 지리적 위치를 검색합니다. 위치는 방향 및 속도에 대한 정보와 함께 일련의 지리 좌표로 표현됩니다. 위치 정보는 Position 개체에 반환됩니다.

예시
다음 코드를 실행하여 현재 위치를 찾을 수 있습니다.
<!DOCTYPE HTML>
<html>
<head>
<script type = "text/javascript">
function showLocation(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
alert("Latitude : " + latitude + " Longitude: " + longitude);
}
function errorHandler(err) {
if(err.code == 1) {
alert("Error: Access is denied!");
}
else if( err.code == 2) {
alert("Error: Position is unavailable!");
}
}
function getLocation(){
if(navigator.geolocation){
// timeout at 60000 milliseconds (60 seconds)
var options = {timeout:60000};
navigator.geolocation.getCurrentPosition(showLocation, errorHandler, options);
} else {
alert("Sorry, browser does not support geolocation!");
}
}
</script>
</head>
<body>
<form>
<input type = "button" onclick = "getLocation();" value = "Get Location"/>
</form>
</body>
</html>