박재윤

지도와 길찾기 api 연결

...@@ -2,77 +2,93 @@ ...@@ -2,77 +2,93 @@
2 <html lang="en"> 2 <html lang="en">
3 <head> 3 <head>
4 <meta charset="UTF-8" /> 4 <meta charset="UTF-8" />
5 - <meta name="viewport" content="width=device-width, initial-scale=1.0" /> 5 + <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
6 <meta http-equiv="X-UA-Compatible" content="ie=edge" /> 6 <meta http-equiv="X-UA-Compatible" content="ie=edge" />
7 - <title>The Town HTML CSS Template</title> 7 + <title>DDuBuk</title>
8 <link rel="stylesheet" href="fontawesome-5.5/css/all.min.css" /> 8 <link rel="stylesheet" href="fontawesome-5.5/css/all.min.css" />
9 <link rel="stylesheet" href="slick/slick.css"> 9 <link rel="stylesheet" href="slick/slick.css">
10 <link rel="stylesheet" href="slick/slick-theme.css"> 10 <link rel="stylesheet" href="slick/slick-theme.css">
11 <link rel="stylesheet" href="magnific-popup/magnific-popup.css"> 11 <link rel="stylesheet" href="magnific-popup/magnific-popup.css">
12 <link rel="stylesheet" href="css/bootstrap.min.css" /> 12 <link rel="stylesheet" href="css/bootstrap.min.css" />
13 <link rel="stylesheet" href="css/templatemo-style.css" /> 13 <link rel="stylesheet" href="css/templatemo-style.css" />
14 - <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/moonspam/NanumBarunGothic@1.0/nanumbarungothicsubset.css"> 14 + <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/moonspam/NanumBarunGothic@1.0/nanumbarungothicsubset.css">
15 - 15 +
16 + <script src="../../docs/js/jquery-1.9.1.js"></script>
17 + <script type="text/javascript" src="../../docs/js/examples-base.js"></script>
18 + <script type="text/javascript" src="../../docs/js/highlight.min.js"></script>
19 + <script type="text/javascript" src="https://openapi.map.naver.com/openapi/v3/maps.js?ncpClientId=rr4owjosjy&submodules=geocoder"></script>
20 + <link rel="stylesheet" type="text/css" href="../../docs/css/examples-base.css" />
16 <!-- 21 <!--
17 The Town 22 The Town
18 https://templatemo.com/tm-525-the-town 23 https://templatemo.com/tm-525-the-town
19 --> 24 -->
25 +
26 + <script type= "text/css">
27 + window.onload = function(){
28 + document.getElementById('btn').onclick = function(){
29 + document.getElementById('frm').submit();
30 + return false;
31 + };
32 +};
33 +
34 +</script>
35 +
20 </head> 36 </head>
21 - <body> 37 + <body>
22 <!-- Hero section --> 38 <!-- Hero section -->
23 <section id="hero" class="text-white tm-font-big tm-parallax"> 39 <section id="hero" class="text-white tm-font-big tm-parallax">
24 <video autoplay muted loop id ="hero-video"> 40 <video autoplay muted loop id ="hero-video">
25 <source src="img/main-video1.mp4" type="video/mp4"> 41 <source src="img/main-video1.mp4" type="video/mp4">
26 </video> 42 </video>
27 <!-- Navigation --> 43 <!-- Navigation -->
28 - <nav class="navbar navbar-expand-md tm-navbar" id="tmNav"> 44 + <nav class="navbar navbar-expand-md tm-navbar" id="tmNav">
29 - <div class="container"> 45 + <div class="container">
30 <div class="tm-next"> 46 <div class="tm-next">
31 <a href="#hero" class="navbar-brand">뚜벅이</a> 47 <a href="#hero" class="navbar-brand">뚜벅이</a>
32 - </div> 48 + </div>
33 </div> 49 </div>
34 </nav> 50 </nav>
35 - 51 +
36 <div class="text-center tm-hero-text-container"> 52 <div class="text-center tm-hero-text-container">
37 <div class="tm-hero-text-container-inner"> 53 <div class="tm-hero-text-container-inner">
38 <h2 class="tm-hero-title">통학생은 길에서 몇시간을 보냈을까?</h2> 54 <h2 class="tm-hero-title">통학생은 길에서 몇시간을 보냈을까?</h2>
39 <p class="tm-hero-subtitle"> 55 <p class="tm-hero-subtitle">
40 매일 학교에 통학하시나요?<br> 56 매일 학교에 통학하시나요?<br>
41 - 뚜벅이님이 지금까지 몇시간을 길에서 보냈는지 보여드립니다. 57 + 뚜벅이님이 지금까지 몇 시간을 길에서 보냈는지 보여드립니다.
42 <br>-뚜벅이- 58 <br>-뚜벅이-
43 </p> 59 </p>
44 - </div> 60 + </div>
45 </div> 61 </div>
46 62
47 <div class="tm-next tm-intro-next"> 63 <div class="tm-next tm-intro-next">
48 <a href="#introduction" class="text-center tm-down-arrow-link"> 64 <a href="#introduction" class="text-center tm-down-arrow-link">
49 - <i class="fas fa-3x fa-caret-down tm-down-arrow">계산해보</i> 65 + <i class="fas fa-3x fa-caret-down tm-down-arrow">계산</i>
50 </a> 66 </a>
51 - </div> 67 + </div>
52 </section> 68 </section>
53 69
54 70
55 71
56 <!-- Contact --> 72 <!-- Contact -->
57 <section id="contact" class="tm-section-pad-top tm-parallax-2"> 73 <section id="contact" class="tm-section-pad-top tm-parallax-2">
58 - <div class="container tm-container-contact"> 74 + <div class="container tm-container-contact">
59 <div class="row"> 75 <div class="row">
60 <div class="container question-field"> 76 <div class="container question-field">
61 <div class="question-text">어디에 사나요?</div> 77 <div class="question-text">어디에 사나요?</div>
62 <div class="question-input"> 78 <div class="question-input">
63 <label for="question-input-field"></label> 79 <label for="question-input-field"></label>
64 - <input type ="text" id="question-input-field"> 80 + <input type ="text" id="start">
65 </div> 81 </div>
66 </div> 82 </div>
67 <div class="container question-field"> 83 <div class="container question-field">
68 - <div class="question-text">무슨학교에 다니나요?</div> 84 + <div class="question-text">무슨 학교에 다니나요?</div>
69 <div class="question-input"> 85 <div class="question-input">
70 <label for="question-input-field"></label> 86 <label for="question-input-field"></label>
71 - <input type ="text" id="question-input-field"> 87 + <input type ="text" id="end">
72 </div> 88 </div>
73 </div> 89 </div>
74 <div class="container question-field"> 90 <div class="container question-field">
75 - <div class="question-text">몇학년인가요?</div> 91 + <div class="question-text"> 학년인가요?</div>
76 <div class="question-input"> 92 <div class="question-input">
77 <select name="semester" id="semester"> 93 <select name="semester" id="semester">
78 <option value="sem-1-1">1학년 1학기</option> 94 <option value="sem-1-1">1학년 1학기</option>
...@@ -87,56 +103,189 @@ ...@@ -87,56 +103,189 @@
87 </div> 103 </div>
88 </div> 104 </div>
89 <div class="container button-field"> 105 <div class="container button-field">
90 - <button class="button_calculate" type="button"> 106 + <button class="button_calculate" type="button">계산하기
91 - 계산해보기
92 </button> 107 </button>
93 </div> 108 </div>
94 </div> 109 </div>
95 - <div class=row id ="map-answer" style="margin-top:100px"> 110 +<br>
96 - <div style="width:30%"> 111 +
97 - <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d203276.83209506533!2d126.94001771640623!3d37.24295009999998!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x357b44de2c7f3ddb%3A0x4c35e852f90f5520!2z6rK97Z2s64yA7ZWZ6rWQIOq1reygnOy6oO2NvOyKpA!5e0!3m2!1sko!2skr!4v1606155147622!5m2!1sko!2skr" width=100% height="250" frameborder="0" style="border:0;" allowfullscreen="" aria-hidden="false" tabindex="0" right="20%"></iframe> 112 +
98 - </div> 113 +<div id="map" style="width:700px;height:700px;"></div>
99 - <div class="answer-field"> 114 +<script>
100 - 한번 갈 때마다 ...<br> 115 +var btn = document.querySelector('button');
101 - <span class="answer-highlight">n</span> 시간 <span class="answer-highlight">n</span><br> 116 +
102 - <span class="answer-highlight">n</span><br> 117 +btn.addEventListener('click', updateBtn);
103 - </div> 118 +
104 - </div> 119 +function updateBtn() {
120 + var start = document.getElementById('start').value;
121 + var end = document.getElementById('end').value;
122 + naver.maps.Service.geocode({
123 + address: start
124 +
125 + }, function(status, response) {
126 + if (status !== naver.maps.Service.Status.OK) {
127 + return alert('Something wrong!');
128 + }
129 + var result = response.result, // 검색 결과의 컨테이너
130 + items = result.items;
131 + var sx = result.items[0].point.x;
132 + var sy = result.items[0].point.y;
133 +
134 + naver.maps.Service.geocode({
135 + address: end
136 +
137 + }, function(status, response) {
138 + if (status !== naver.maps.Service.Status.OK) {
139 + return alert('Something wrong!');
140 + }
141 + var result = response.result, // 검색 결과의 컨테이너
142 + items = result.items;
143 + var ex = result.items[0].point.x;
144 + var ey = result.items[0].point.y;
145 +
146 +
147 + /*var sx = 127.0739547;
148 + var sy = 37.2407701;
149 + var ex = 126.921666;
150 + var ey = 37.1308333;
151 + */
152 +
153 +
154 + var mapOptions = {
155 + center: new naver.maps.LatLng(start,end),
156 + zoom: 10
157 + };
158 +
159 + var map = new naver.maps.Map('map', mapOptions);
160 +
161 +
162 +
163 + function searchPubTransPathAJAX() {
164 + var xhr = new XMLHttpRequest();
165 + //ODsay apiKey 입력
166 + var url = "https://api.odsay.com/v1/api/searchPubTransPath?SX="+sx+"&SY="+sy+"&EX="+ex+"&EY="+ey+"&apiKey=nnsDQB1AWhpETO3HmMdDAw";
167 + xhr.open("GET", url, true);
168 + xhr.send();
169 + xhr.onreadystatechange = function() {
170 + if (xhr.readyState == 4 && xhr.status == 200) {
171 + console.log( JSON.parse(xhr.responseText) ); // <- xhr.responseText 로 결과를 가져올 수 있음
172 + //노선그래픽 데이터 호출
173 + callMapObjApiAJAX((JSON.parse(xhr.responseText))["result"]["path"][0].info.mapObj);
174 + }
175 + }
176 + }
177 +
178 + //길찾기 API 호출
179 + searchPubTransPathAJAX();
180 +
181 + function callMapObjApiAJAX(mabObj){
182 + var xhr = new XMLHttpRequest();
183 + //ODsay apiKey 입력
184 + var url = "https://api.odsay.com/v1/api/loadLane?mapObject=0:0@"+mabObj+"&apiKey=nnsDQB1AWhpETO3HmMdDAw";
185 + xhr.open("GET", url, true);
186 + xhr.send();
187 + xhr.onreadystatechange = function() {
188 + if (xhr.readyState == 4 && xhr.status == 200) {
189 + var resultJsonData = JSON.parse(xhr.responseText);
190 + drawNaverMarker(sx,sy); // 출발지 마커 표시
191 + drawNaverMarker(ex,ey); // 도착지 마커 표시
192 + drawNaverPolyLine(resultJsonData); // 노선그래픽데이터 지도위 표시
193 + // boundary 데이터가 있을경우, 해당 boundary로 지도이동
194 + if(resultJsonData.result.boundary){
195 + var boundary = new naver.maps.LatLngBounds(
196 + new naver.maps.LatLng(resultJsonData.result.boundary.top, resultJsonData.result.boundary.left),
197 + new naver.maps.LatLng(resultJsonData.result.boundary.bottom, resultJsonData.result.boundary.right)
198 + );
199 + map.panToBounds(boundary);
200 + }
201 + }
202 + }
203 + }
204 +
205 + // 지도위 마커 표시해주는 함수
206 + function drawNaverMarker(x,y){
207 + var marker = new naver.maps.Marker({
208 + position: new naver.maps.LatLng(y, x),
209 + map: map
210 + });
211 + }
212 +
213 + // 노선그래픽 데이터를 이용하여 지도위 폴리라인 그려주는 함수
214 + function drawNaverPolyLine(data){
215 + var lineArray;
216 +
217 + for(var i = 0 ; i < data.result.lane.length; i++){
218 + for(var j=0 ; j <data.result.lane[i].section.length; j++){
219 + lineArray = null;
220 + lineArray = new Array();
221 + for(var k=0 ; k < data.result.lane[i].section[j].graphPos.length; k++){
222 + lineArray.push(new naver.maps.LatLng(data.result.lane[i].section[j].graphPos[k].y, data.result.lane[i].section[j].graphPos[k].x));
223 + }
224 +
225 + //지하철결과의 경우 노선에 따른 라인색상 지정하는 부분 (1,2호선의 경우만 예로 들음)
226 + if(data.result.lane[i].type == 1){
227 + var polyline = new naver.maps.Polyline({
228 + map: map,
229 + path: lineArray,
230 + strokeWeight: 3,
231 + strokeColor: '#003499'
232 + });
233 + }else if(data.result.lane[i].type == 2){
234 + var polyline = new naver.maps.Polyline({
235 + map: map,
236 + path: lineArray,
237 + strokeWeight: 3,
238 + strokeColor: '#37b42d'
239 + });
240 + }else{
241 + var polyline = new naver.maps.Polyline({
242 + map: map,
243 + path: lineArray,
244 + strokeWeight: 3
245 + });
246 + }
247 + }
248 + }
249 + }
250 + });
251 + });
252 +}
253 +</script>
254 +
105 <div class="row"> 255 <div class="row">
106 <div id="list-answer"> 256 <div id="list-answer">
107 <div class="answer-field" id="answer-how-many-hours"> 257 <div class="answer-field" id="answer-how-many-hours">
108 - 지금까지 <span class="answer-highlight">n</span>시간을 길에서 보내셨군요<br> 258 + 지금까지 <span class="answer-highlight">n</span> 시간을 길에서 보내셨군요!<br>
109 - 졸업까지 앞으로 <span class="answer-highlight">n</span>시간은 더 길에서 보내시면 됩니다.<br> 259 + 앞으로 <span class="answer-highlight">n</span> 시간은 더 길에서 보내시면 됩니다!!<br>
110 </div> 260 </div>
111 </div> 261 </div>
112 </div> 262 </div>
113 - <div class="row"> 263 + <div class="row">
114 - <div class = "answer-detail-question"> 264 + <div id="list-answer">
115 - 이 시간에 알바를 했다면? <br> 265 + <div class="answer-field" id="answer-how-many-hours">
116 - 교통비로 국밥 <br> 266 + <p>이 시간에..</p>
117 - </div> 267 + 알바를 했다면? <span class="answer-highlight">n</span><br>
118 - <div class="answer-detail-answer"> 268 + <p>이 돈이면..</p>
119 - n원<br> 269 + 국밥이 <span class="answer-highlight">n</span> 그릇<br>
120 - m그릇<br> 270 + </div>
121 - </div> 271 + </div>
122 - </div> 272 + </div>
123 - </div>
124 <footer class="text-center small tm-footer"> 273 <footer class="text-center small tm-footer">
125 <p class="mb-0"> 274 <p class="mb-0">
126 Copyright &copy; 2020 TongGilMut 275 Copyright &copy; 2020 TongGilMut
127 - 276 +
128 - Design: <a rel="nofollow" href="https://github.com/wjdwl001" class="tm-footer-link">Joung Jiwon</a> 277 - Design: <a rel="nofollow" href="https://github.com/wjdwl001" class="tm-footer-link">Joung Jiwon</a>
129 </p> 278 </p>
130 </footer> 279 </footer>
131 </section> 280 </section>
132 - <script src="js/jquery-1.9.1.min.js"></script> 281 + <script src="js/jquery-1.9.1.min.js"></script>
133 <script src="slick/slick.min.js"></script> 282 <script src="slick/slick.min.js"></script>
134 <script src="magnific-popup/jquery.magnific-popup.min.js"></script> 283 <script src="magnific-popup/jquery.magnific-popup.min.js"></script>
135 - <script src="js/jquery.singlePageNav.min.js"></script> 284 + <script src="js/jquery.singlePageNav.min.js"></script>
136 - <script src="js/bootstrap.min.js"></script> 285 + <script src="js/bootstrap.min.js"></script>
137 <script> 286 <script>
138 $('button-calculate').click(function(){ 287 $('button-calculate').click(function(){
139 - 288 +
140 }) 289 })
141 290
142 function getOffSet(){ 291 function getOffSet(){
...@@ -145,7 +294,7 @@ ...@@ -145,7 +294,7 @@
145 294
146 if(windowHeight > 500) { 295 if(windowHeight > 500) {
147 _offset = 400; 296 _offset = 400;
148 - } 297 + }
149 if(windowHeight > 680) { 298 if(windowHeight > 680) {
150 _offset = 300 299 _offset = 300
151 } 300 }
...@@ -164,7 +313,7 @@ ...@@ -164,7 +313,7 @@
164 } 313 }
165 314
166 // Parallax function 315 // Parallax function
167 - // Adapted based on https://codepen.io/roborich/pen/wpAsm 316 + // Adapted based on https://codepen.io/roborich/pen/wpAsm
168 var background_image_parallax = function($object, multiplier, forceSet){ 317 var background_image_parallax = function($object, multiplier, forceSet){
169 multiplier = typeof multiplier !== 'undefined' ? multiplier : 0.5; 318 multiplier = typeof multiplier !== 'undefined' ? multiplier : 0.5;
170 multiplier = 1 - multiplier; 319 multiplier = 1 - multiplier;
...@@ -174,7 +323,7 @@ ...@@ -174,7 +323,7 @@
174 if(forceSet) { 323 if(forceSet) {
175 setParallaxPosition($doc, multiplier, $object); 324 setParallaxPosition($doc, multiplier, $object);
176 } else { 325 } else {
177 - $(window).scroll(function(){ 326 + $(window).scroll(function(){
178 setParallaxPosition($doc, multiplier, $object); 327 setParallaxPosition($doc, multiplier, $object);
179 }); 328 });
180 } 329 }
...@@ -188,41 +337,41 @@ ...@@ -188,41 +337,41 @@
188 $(window).scroll(function(){ 337 $(window).scroll(function(){
189 var firstTop = $object.offset().top, 338 var firstTop = $object.offset().top,
190 pos = $(window).scrollTop(), 339 pos = $(window).scrollTop(),
191 - yPos = Math.round((multiplier * (firstTop - pos)) - 186); 340 + yPos = Math.round((multiplier * (firstTop - pos)) - 186);
192 341
193 var bg_css = 'center ' + yPos + 'px'; 342 var bg_css = 'center ' + yPos + 'px';
194 343
195 $object.css({"background-position" : bg_css }); 344 $object.css({"background-position" : bg_css });
196 }); 345 });
197 }; 346 };
198 - 347 +
199 $(function(){ 348 $(function(){
200 // Hero Section - Background Parallax 349 // Hero Section - Background Parallax
201 background_image_parallax($(".tm-parallax"), 0.30, false); 350 background_image_parallax($(".tm-parallax"), 0.30, false);
202 - background_image_parallax_2($("#contact"), 0.80); 351 + background_image_parallax_2($("#contact"), 0.80);
203 - 352 +
204 // Handle window resize 353 // Handle window resize
205 window.addEventListener('resize', function(){ 354 window.addEventListener('resize', function(){
206 background_image_parallax($(".tm-parallax"), 0.30, true); 355 background_image_parallax($(".tm-parallax"), 0.30, true);
207 }, true); 356 }, true);
208 357
209 // Detect window scroll and update navbar 358 // Detect window scroll and update navbar
210 - $(window).scroll(function(e){ 359 + $(window).scroll(function(e){
211 if($(document).scrollTop() > 120) { 360 if($(document).scrollTop() > 120) {
212 $('.tm-navbar').addClass("scroll"); 361 $('.tm-navbar').addClass("scroll");
213 } else { 362 } else {
214 $('.tm-navbar').removeClass("scroll"); 363 $('.tm-navbar').removeClass("scroll");
215 } 364 }
216 }); 365 });
217 - 366 +
218 - // Close mobile menu after click 367 + // Close mobile menu after click
219 $('#tmNav a').on('click', function(){ 368 $('#tmNav a').on('click', function(){
220 - $('.navbar-collapse').removeClass('show'); 369 + $('.navbar-collapse').removeClass('show');
221 }) 370 })
222 371
223 // Scroll to corresponding section with animation 372 // Scroll to corresponding section with animation
224 - $('#tmNav').singlePageNav(); 373 + $('#tmNav').singlePageNav();
225 - 374 +
226 // Add smooth scrolling to all links 375 // Add smooth scrolling to all links
227 // https://www.w3schools.com/howto/howto_css_smooth_scroll.asp 376 // https://www.w3schools.com/howto/howto_css_smooth_scroll.asp
228 $("a").on('click', function(event) { 377 $("a").on('click', function(event) {
...@@ -278,4 +427,4 @@ ...@@ -278,4 +427,4 @@
278 }); 427 });
279 </script> 428 </script>
280 </body> 429 </body>
281 -</html>
...\ No newline at end of file ...\ No newline at end of file
430 +</html>
......