1. 참고 사이트 링크
1. HTML 파일에 코드 추가
2. 완성 화면
0. 참고 사이트 링크
https://navermaps.github.io/maps.js/docs/tutorial-6-map-geolocation.example.html
NAVER Maps API v3
NAVER Maps API v3로 여러분의 지도를 만들어 보세요. 유용한 기술문서와 다양한 예제 코드를 제공합니다.
navermaps.github.io
1. HTML 파일에 코드 추가
var map = new naver.maps.Map('map', {
center: new naver.maps.LatLng(37.5666805, 126.9784147),
zoom: 10,
mapTypeId: naver.maps.MapTypeId.NORMAL
});
var infowindow = new naver.maps.InfoWindow();
function onSuccessGeolocation(position) {
var location = new naver.maps.LatLng(position.coords.latitude,
position.coords.longitude);
map.setCenter(location); // 얻은 좌표를 지도의 중심으로 설정합니다.
map.setZoom(10); // 지도의 줌 레벨을 변경합니다.
infowindow.setContent('<div style="padding:20px;">' + 'geolocation.getCurrentPosition() 위치' + '</div>');
infowindow.open(map, location);
console.log('Coordinates: ' + location.toString());
}
function onErrorGeolocation() {
var center = map.getCenter();
infowindow.setContent('<div style="padding:20px;">' +
'<h5 style="margin-bottom:5px;color:#f00;">Geolocation failed!</h5>'+ "latitude: "+ center.lat() +"<br />longitude: "+ center.lng() +'</div>');
infowindow.open(map, center);
}
$(window).on("load", function() {
if (navigator.geolocation) {
/**
* navigator.geolocation 은 Chrome 50 버젼 이후로 HTTP 환경에서 사용이 Deprecate 되어 HTTPS 환경에서만 사용 가능 합니다.
* http://localhost 에서는 사용이 가능하며, 테스트 목적으로, Chrome 의 바로가기를 만들어서 아래와 같이 설정하면 접속은 가능합니다.
* chrome.exe --unsafely-treat-insecure-origin-as-secure="http://example.com"
*/
navigator.geolocation.getCurrentPosition(onSuccessGeolocation, onErrorGeolocation);
} else {
var center = map.getCenter();
infowindow.setContent('<div style="padding:20px;"><h5 style="margin-bottom:5px;color:#f00;">Geolocation not supported</h5></div>');
infowindow.open(map, center);
}
});
2. 완성 화면
'Language > Springboot' 카테고리의 다른 글
[Springboot] Jsoup 이용하여 웹 크롤링하기 (0) | 2022.09.27 |
---|---|
[Springboot] 회원 정보(닉네임) 수정하기 (+추가 기능 구현 중) (0) | 2022.08.31 |
[Stringboot] 제이쿼리(jQuery) 적용하기 (0) | 2022.08.28 |
[Springboot] 웹에 네이버지도 API 추가하기 (0) | 2022.08.26 |
[Stringboot] 게시글 댓글 페이징 기능 구현하기 (1) | 2022.08.25 |