dckat

중심좌표 현재위치로 구현

1 -{"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"},"__lastAccess":1620820123092,"user":{"name":"‍김대철[학생](소프트웨어융합대학 컴퓨터공학과)","email":"kdc9619@khu.ac.kr","picture":"https://lh3.googleusercontent.com/a/AATXAJyP14ipRboJZ8T5-oNS3sRp4CG8wKCEwVABQ5G_=s96-c"}}
...\ No newline at end of file ...\ No newline at end of file
1 +{"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"},"__lastAccess":1620823546959,"user":{"name":"‍김대철[학생](소프트웨어융합대학 컴퓨터공학과)","email":"kdc9619@khu.ac.kr","picture":"https://lh3.googleusercontent.com/a/AATXAJyP14ipRboJZ8T5-oNS3sRp4CG8wKCEwVABQ5G_=s96-c"}}
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -12,13 +12,40 @@ ...@@ -12,13 +12,40 @@
12 src="//dapi.kakao.com/v2/maps/sdk.js?appkey=68cbccbcd6f0fef0a213e62ad37393ee" 12 src="//dapi.kakao.com/v2/maps/sdk.js?appkey=68cbccbcd6f0fef0a213e62ad37393ee"
13 ></script> 13 ></script>
14 <script> 14 <script>
15 - const mapContainer = document.getElementById("map"), 15 + var lat = "";
16 + var lon = "";
17 +
18 + var mapContainer = document.getElementById("map"),
16 mapOption = { 19 mapOption = {
17 - center: new kakao.maps.LatLng(37.2477502, 127.078164), 20 + center: new kakao.maps.LatLng(36.2477502, 127.078164),
18 level: 3, 21 level: 3,
19 }; 22 };
20 23
21 - const map = new kakao.maps.Map(mapContainer, mapOption); 24 + var map = new kakao.maps.Map(mapContainer, mapOption);
25 +
26 + if (navigator.geolocation) {
27 + navigator.geolocation.getCurrentPosition(function (position) {
28 + lat = position.coords.latitude;
29 + lon = position.coords.longitude;
30 +
31 + var locPosition = new kakao.maps.LatLng(lat, lon);
32 +
33 + displayMarker(locPosition);
34 + });
35 + } else {
36 + var locPosition = new kakao.maps.LatLng(36.2477502, 127.078164);
37 +
38 + displayMarker(locPosition);
39 + }
40 +
41 + function displayMarker(locPosition) {
42 + var marker = new daum.maps.Marker({
43 + map: map,
44 + position: locPosition,
45 + });
46 +
47 + map.setCenter(locPosition);
48 + }
22 </script> 49 </script>
23 </body> 50 </body>
24 </html> 51 </html>
......