🔗Maps JavaScript API 가이드: Show current location
This example creates a map that displays the geographic location of a user or device on a Google map, through use of their browser's HTML5 Geolocation feature.
let map = new google.maps.Map(document.getElementById('map'), {
center: { lat: 37, lng: 126 },
zoom: 12
});
// 현재 위치 표시
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position){
let pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
map.setCenter(pos);
}, function(){
handleLocationError(false, infoWindow, map.getCenter());
});
}else {
handleLocationError(false, infoWindow, map.getCenter());
}
function handleLocationError(browerHasGeolocation, infoWindow, pos){
infoWindow.setPosition(pos);
infoWindow.setContent(browserHasGeolocation ?
'오류: 지오로케이션 연결 실패' :
'오류: 브라우저에서 지오로케이션을 지원하지 않음');
}