이준용

현재 위치 표시기능 추가

<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>다음 지도 API</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://dapi.kakao.com/v2/maps/sdk.js?appkey=9e4f94c8089b558cf9d25a267a86eea9&libraries=clusterer"></script>
</head>
<body>
<div id="map" style="width:100%;height:100vh;"></div>
<script
src="https://dapi.kakao.com/v2/maps/sdk.js?appkey=9e4f94c8089b558cf9d25a267a86eea9&libraries=clusterer"></script>
<script>
$.get("https://openapi.gg.go.kr/RegionMnyFacltStus?Type=json", function (data) {
alert("Data: " + data);
});
var myJson = "{\"lat\":37, \"lng\":130}";
var parsedJson = JSON.parse(myJson);
console.log("originalJson: " + myJson);
console.log(parsedJson);
// document.querySelector('#find-me').addEventListener('click', geoFindMe);
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function success(pos) {
var crd = pos.coords;
console.log('Your current position is:');
console.log('Latitude : ' + crd.latitude);
console.log('Longitude: ' + crd.longitude);
console.log('More or less ' + crd.accuracy + ' meters.');
setLocation(crd.latitude, crd.longitude);
};
function error(err) {
console.warn('ERROR(' + err.code + '): ' + err.message);
};
function setLocation(lat, lng) {
// 이동할 위도 경도 위치를 생성합니다
var moveLatLon = new kakao.maps.LatLng(lat, lng);
// 지도 중심을 이동 시킵니다
map.setCenter(moveLatLon);
}
console.log(navigator.geolocation.getCurrentPosition(success, error, options));
var mapContainer = document.getElementById('map'), // 지도를 표시할 div
mapOption = {
center: new kakao.maps.LatLng(37.350040, 127.108901), // 지도의 중심좌표
......@@ -78,8 +119,11 @@
}
// 아래 코드는 인포윈도우를 지도에서 제거합니다
// infowindow.close();
</script>
</body>
......