Showing
4 changed files
with
308 additions
and
250 deletions
1 | var express = require("express"); | 1 | var express = require("express"); |
2 | var router = express.Router(); | 2 | var router = express.Router(); |
3 | 3 | ||
4 | -var request = require("request"); | ||
5 | var bodyParser = require("body-parser"); | 4 | var bodyParser = require("body-parser"); |
6 | 5 | ||
7 | var { OAuth2Client } = require("google-auth-library"); | 6 | var { OAuth2Client } = require("google-auth-library"); |
8 | -var querystring = require("querystring"); | ||
9 | 7 | ||
10 | var CLIENT_ID = | 8 | var CLIENT_ID = |
11 | "94679084723-s5f0686p2porp9mkakrp1p89a48n24nj.apps.googleusercontent.com"; | 9 | "94679084723-s5f0686p2porp9mkakrp1p89a48n24nj.apps.googleusercontent.com"; |
... | @@ -13,15 +11,18 @@ var client = new OAuth2Client(CLIENT_ID); | ... | @@ -13,15 +11,18 @@ var client = new OAuth2Client(CLIENT_ID); |
13 | var mysql = require("mysql"); | 11 | var mysql = require("mysql"); |
14 | var session = require("express-session"); | 12 | var session = require("express-session"); |
15 | var FileStore = require("session-file-store")(session); | 13 | var FileStore = require("session-file-store")(session); |
14 | + | ||
16 | router.use(bodyParser.urlencoded({ extended: false })); //url인코딩 x | 15 | router.use(bodyParser.urlencoded({ extended: false })); //url인코딩 x |
17 | -router.use(bodyParser.json()); //json방식으로 파 | 16 | +router.use(bodyParser.json()); //json방식으로 파싱 |
18 | router.use( | 17 | router.use( |
19 | session({ | 18 | session({ |
20 | secret: "209", // 암호화 | 19 | secret: "209", // 암호화 |
21 | resave: false, | 20 | resave: false, |
22 | saveUninitialized: true, | 21 | saveUninitialized: true, |
23 | store: new FileStore(), | 22 | store: new FileStore(), |
24 | - })) | 23 | + }) |
24 | +); | ||
25 | + | ||
25 | var connection = mysql.createConnection({ | 26 | var connection = mysql.createConnection({ |
26 | host: "localhost", | 27 | host: "localhost", |
27 | user: "root", | 28 | user: "root", |
... | @@ -29,6 +30,7 @@ var connection = mysql.createConnection({ | ... | @@ -29,6 +30,7 @@ var connection = mysql.createConnection({ |
29 | database: "caferecommend", | 30 | database: "caferecommend", |
30 | }); | 31 | }); |
31 | connection.connect(); | 32 | connection.connect(); |
33 | + | ||
32 | /* GET home page. */ | 34 | /* GET home page. */ |
33 | router.get("/", function (req, res, next) { | 35 | router.get("/", function (req, res, next) { |
34 | res.render("index", { | 36 | res.render("index", { |
... | @@ -49,7 +51,7 @@ router.post("/index", (req, res) => { | ... | @@ -49,7 +51,7 @@ router.post("/index", (req, res) => { |
49 | audience: CLIENT_ID, // Specify the CLIENT_ID of the app that accesses the backend | 51 | audience: CLIENT_ID, // Specify the CLIENT_ID of the app that accesses the backend |
50 | }); | 52 | }); |
51 | const payload = ticket.getPayload(); | 53 | const payload = ticket.getPayload(); |
52 | - const userid = payload['sub'] | 54 | + const userid = payload["sub"]; |
53 | } | 55 | } |
54 | verify() | 56 | verify() |
55 | .then(() => { | 57 | .then(() => { |
... | @@ -61,7 +63,7 @@ router.post("/index", (req, res) => { | ... | @@ -61,7 +63,7 @@ router.post("/index", (req, res) => { |
61 | 63 | ||
62 | router.get("/login", checkAuthenticated, (req, res) => { | 64 | router.get("/login", checkAuthenticated, (req, res) => { |
63 | let user = req.user; | 65 | let user = req.user; |
64 | - req.session.user=user; | 66 | + req.session.user = user; |
65 | var sql = "SELECT * FROM USER WHERE EMAIL=?"; | 67 | var sql = "SELECT * FROM USER WHERE EMAIL=?"; |
66 | var parameter = [req.session.user.email]; | 68 | var parameter = [req.session.user.email]; |
67 | connection.query(sql, parameter, function (err, row) { | 69 | connection.query(sql, parameter, function (err, row) { |
... | @@ -111,7 +113,7 @@ router.post("/login", (req, res) => { | ... | @@ -111,7 +113,7 @@ router.post("/login", (req, res) => { |
111 | req.session.user.age, | 113 | req.session.user.age, |
112 | req.session.user.gender, | 114 | req.session.user.gender, |
113 | ]; | 115 | ]; |
114 | - connection.query(sql, parameter, function (err, row) { | 116 | + connection.query(sql, parameter, function (err) { |
115 | if (err) { | 117 | if (err) { |
116 | console.log(err); | 118 | console.log(err); |
117 | } else { | 119 | } else { |
... | @@ -123,8 +125,6 @@ router.post("/login", (req, res) => { | ... | @@ -123,8 +125,6 @@ router.post("/login", (req, res) => { |
123 | }); | 125 | }); |
124 | }); | 126 | }); |
125 | 127 | ||
126 | -module.exports = router; | ||
127 | - | ||
128 | function checkAuthenticated(req, res, next) { | 128 | function checkAuthenticated(req, res, next) { |
129 | let token = req.cookies["session-token"]; | 129 | let token = req.cookies["session-token"]; |
130 | let user = {}; | 130 | let user = {}; |
... | @@ -158,3 +158,34 @@ router.get("/logout", function (req, res) { | ... | @@ -158,3 +158,34 @@ router.get("/logout", function (req, res) { |
158 | req.session.destroy(); //세션비우기 | 158 | req.session.destroy(); //세션비우기 |
159 | res.redirect("/"); | 159 | res.redirect("/"); |
160 | }); | 160 | }); |
161 | + | ||
162 | +// 카페 후기 등록 | ||
163 | +router.post("/comment", function (req, res) { | ||
164 | + var cafeId = req.body.cafeId; | ||
165 | + var price = req.body.price; | ||
166 | + var kindness = req.body.kindness; | ||
167 | + var noise = req.body.noise; | ||
168 | + var accessibility = req.body.accessibility; | ||
169 | + | ||
170 | + // 입력받지 않은 데이터가 하나라도 존재 (카페아이디는 후기작성시 자동으로 받아옴) | ||
171 | + if (!price || !kindness || !noise || !accessibility) { | ||
172 | + console.log("입력받지 않은 데이터 존재"); | ||
173 | + return; // 후기작성으로 다시 이동 | ||
174 | + } | ||
175 | + | ||
176 | + var sql = | ||
177 | + "INSERT INTO COMMENT(CAFE_ID, PRICE, KINDNESS, NOISE, ACCESSIBILITY) VALUES(?,?,?,?,?)"; | ||
178 | + | ||
179 | + var parameter = [cafeId, price, kindness, noise, accessibility]; | ||
180 | + | ||
181 | + connection.query(sql, parameter, function (err) { | ||
182 | + if (err) { | ||
183 | + console.log(err); | ||
184 | + } else { | ||
185 | + console.log("새로운 comment 데이터 입력"); | ||
186 | + } | ||
187 | + }); | ||
188 | + return res.render("map"); | ||
189 | +}); | ||
190 | + | ||
191 | +module.exports = router; | ... | ... |
1 | +{"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"},"__lastAccess":1621766908867,"user":{"name":"김대철[학생](소프트웨어융합대학 컴퓨터공학과)","email":"kdc9619@khu.ac.kr","nickname":"Meerkat","age":"26","gender":"male"}} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +{"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"},"__lastAccess":1621952163379} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | <!DOCTYPE html> | 1 | <!DOCTYPE html> |
2 | <html> | 2 | <html> |
3 | -<head> | 3 | + <head> |
4 | - <link rel="stylesheet" href="stylesheets/bootstrap.css"> | 4 | + <link rel="stylesheet" href="stylesheets/bootstrap.css" /> |
5 | - <title>Cafe Map</title> | 5 | + <title>Cafe Map</title> |
6 | - <style> | 6 | + <style> |
7 | - .navbar{ | 7 | + .navbar { |
8 | - background-color: #1d2124 !important; | 8 | + background-color: #1d2124 !important; |
9 | - } | 9 | + } |
10 | - .btn-primary{ | 10 | + .btn-primary { |
11 | - color : white !important; | 11 | + color: white !important; |
12 | - } | 12 | + } |
13 | - p{font-family: 'Noto Sans KR', sans-serif;} | 13 | + p { |
14 | - h1{font-family: 'Noto Sans KR', sans-serif;} | 14 | + font-family: "Noto Sans KR", sans-serif; |
15 | - h4{font-family: 'Noto Sans KR', sans-serif;} | 15 | + } |
16 | - h2{font-family: 'Noto Sans KR', sans-serif;} | 16 | + h1 { |
17 | - h3{font-family: 'Noto Sans KR', sans-serif;} | 17 | + font-family: "Noto Sans KR", sans-serif; |
18 | - h5{font-family: 'Noto Sans KR', sans-serif;} | 18 | + } |
19 | - .placeinfo_wrap { | 19 | + h4 { |
20 | - position: absolute; | 20 | + font-family: "Noto Sans KR", sans-serif; |
21 | - bottom: 28px; | 21 | + } |
22 | - left: -150px; | 22 | + h2 { |
23 | - width: 300px; | 23 | + font-family: "Noto Sans KR", sans-serif; |
24 | - } | 24 | + } |
25 | - .placeinfo { | 25 | + h3 { |
26 | - position: relative; | 26 | + font-family: "Noto Sans KR", sans-serif; |
27 | - width: 100%; | 27 | + } |
28 | - border-radius: 6px; | 28 | + h5 { |
29 | - border: 1px solid #ccc; | 29 | + font-family: "Noto Sans KR", sans-serif; |
30 | - border-bottom: 2px solid #ddd; | 30 | + } |
31 | - padding-bottom: 10px; | 31 | + .placeinfo_wrap { |
32 | - background: #fff; | 32 | + position: absolute; |
33 | - } | 33 | + bottom: 28px; |
34 | - .placeinfo:nth-of-type(n) { | 34 | + left: -150px; |
35 | - border: 0; | 35 | + width: 300px; |
36 | - box-shadow: 0px 1px 2px #888; | 36 | + } |
37 | - } | 37 | + .placeinfo { |
38 | - .placeinfo_wrap .after { | 38 | + position: relative; |
39 | - content: ""; | 39 | + width: 100%; |
40 | - position: relative; | 40 | + border-radius: 6px; |
41 | - margin-left: -12px; | 41 | + border: 1px solid #ccc; |
42 | - left: 50%; | 42 | + border-bottom: 2px solid #ddd; |
43 | - width: 22px; | 43 | + padding-bottom: 10px; |
44 | - height: 12px; | 44 | + background: #fff; |
45 | - background: url("https://t1.daumcdn.net/localimg/localimages/07/mapapidoc/vertex_white.png"); | 45 | + } |
46 | - } | 46 | + .placeinfo:nth-of-type(n) { |
47 | - .placeinfo a, | 47 | + border: 0; |
48 | - .placeinfo a:hover, | 48 | + box-shadow: 0px 1px 2px #888; |
49 | - .placeinfo a:active { | 49 | + } |
50 | - color: #fff; | 50 | + .placeinfo_wrap .after { |
51 | - text-decoration: none; | 51 | + content: ""; |
52 | - } | 52 | + position: relative; |
53 | - .placeinfo a, | 53 | + margin-left: -12px; |
54 | - .placeinfo span { | 54 | + left: 50%; |
55 | - display: block; | 55 | + width: 22px; |
56 | - text-overflow: ellipsis; | 56 | + height: 12px; |
57 | - overflow: hidden; | 57 | + background: url("https://t1.daumcdn.net/localimg/localimages/07/mapapidoc/vertex_white.png"); |
58 | - white-space: nowrap; | 58 | + } |
59 | - } | 59 | + .placeinfo a, |
60 | - .placeinfo span { | 60 | + .placeinfo a:hover, |
61 | - margin: 5px 5px 0 5px; | 61 | + .placeinfo a:active { |
62 | - cursor: default; | 62 | + color: #fff; |
63 | - font-size: 13px; | 63 | + text-decoration: none; |
64 | - } | 64 | + } |
65 | - .placeinfo .title { | 65 | + .placeinfo a, |
66 | - font-weight: bold; | 66 | + .placeinfo span { |
67 | - font-size: 14px; | 67 | + display: block; |
68 | - border-radius: 6px 6px 0 0; | 68 | + text-overflow: ellipsis; |
69 | - margin: -1px -1px 0 -1px; | 69 | + overflow: hidden; |
70 | - padding: 10px; | 70 | + white-space: nowrap; |
71 | - color: #fff; | 71 | + } |
72 | - background: #d95050; | 72 | + .placeinfo span { |
73 | - background: #d95050 | 73 | + margin: 5px 5px 0 5px; |
74 | - url(https://t1.daumcdn.net/localimg/localimages/07/mapapidoc/arrow_white.png) | 74 | + cursor: default; |
75 | - no-repeat right 14px center; | 75 | + font-size: 13px; |
76 | - } | 76 | + } |
77 | - .placeinfo .tel { | 77 | + .placeinfo .title { |
78 | - color: #0f7833; | 78 | + font-weight: bold; |
79 | - } | 79 | + font-size: 14px; |
80 | - .placeinfo .jibun { | 80 | + border-radius: 6px 6px 0 0; |
81 | - color: #999; | 81 | + margin: -1px -1px 0 -1px; |
82 | - font-size: 11px; | 82 | + padding: 10px; |
83 | - margin-top: 0; | 83 | + color: #fff; |
84 | - } | 84 | + background: #d95050; |
85 | - </style> | 85 | + background: #d95050 |
86 | -</head> | 86 | + url(https://t1.daumcdn.net/localimg/localimages/07/mapapidoc/arrow_white.png) |
87 | -<body> | 87 | + no-repeat right 14px center; |
88 | -<nav class="navbar navbar-expand-lg navbar-dark bg-dark"> | 88 | + } |
89 | - <a class="navbar-brand" href="/"><img src="images/home.png" width="40" height="40" alt=""> | 89 | + .placeinfo .tel { |
90 | - </a> | 90 | + color: #0f7833; |
91 | - <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> | 91 | + } |
92 | - <span class="navbar-toggler-icon"></span> | 92 | + .placeinfo .jibun { |
93 | - </button> | 93 | + color: #999; |
94 | - <div class="collapse navbar-collapse" id="navbarSupportedContent"> | 94 | + font-size: 11px; |
95 | - <a class="navbar-brand" href="/" ><strong>Home</strong></a> | 95 | + margin-top: 0; |
96 | - <ul class="navbar-nav mr-auto mt-2 mt-lg-0"> | 96 | + } |
97 | + </style> | ||
98 | + </head> | ||
99 | + <body> | ||
100 | + <nav class="navbar navbar-expand-lg navbar-dark bg-dark"> | ||
101 | + <a class="navbar-brand" href="/" | ||
102 | + ><img src="images/home.png" width="40" height="40" alt="" /> | ||
103 | + </a> | ||
104 | + <button | ||
105 | + class="navbar-toggler" | ||
106 | + type="button" | ||
107 | + data-toggle="collapse" | ||
108 | + data-target="#navbarSupportedContent" | ||
109 | + aria-controls="navbarSupportedContent" | ||
110 | + aria-expanded="false" | ||
111 | + aria-label="Toggle navigation" | ||
112 | + > | ||
113 | + <span class="navbar-toggler-icon"></span> | ||
114 | + </button> | ||
115 | + <div class="collapse navbar-collapse" id="navbarSupportedContent"> | ||
116 | + <a class="navbar-brand" href="/"><strong>Home</strong></a> | ||
117 | + <ul class="navbar-nav mr-auto mt-2 mt-lg-0"> | ||
118 | + <li class="nav-item active"> | ||
119 | + <a | ||
120 | + class="nav-link" | ||
121 | + style="color: #ffffff" | ||
122 | + href="/" | ||
123 | + onclick="signOut();" | ||
124 | + >Logout<span class="sr-only">(current)</span></a | ||
125 | + > | ||
126 | + </li> | ||
127 | + </ul> | ||
128 | + </div> | ||
129 | + </nav> | ||
130 | + <div class="pricing-header px-3 py-1 pt-md-3 pb-md-1 mx-auto text-center"> | ||
131 | + <h3 class="display-6 font-weight-bold">Map</h3> | ||
132 | + </div> | ||
97 | 133 | ||
98 | - <li class="nav-item active"> | 134 | + <div id="map" style="width: 100%; height: 575px"></div> |
99 | - <a class="nav-link" style="color:#ffffff" href="/" onclick="signOut();">Logout<span class="sr-only">(current)</span></a> | 135 | + <script |
100 | - </li> | 136 | + type="text/javascript" |
101 | - | 137 | + src="//dapi.kakao.com/v2/maps/sdk.js?appkey=68cbccbcd6f0fef0a213e62ad37393ee&libraries=services" |
102 | - </ul> | 138 | + ></script> |
103 | - </div> | 139 | + <script> |
104 | -</nav> | 140 | + var lat = ""; |
105 | -<div class="pricing-header px-3 py-1 pt-md-3 pb-md-1 mx-auto text-center"> | 141 | + var lon = ""; |
106 | - <h3 class="display-6 font-weight-bold" >Map</h3> | 142 | + var placeOverlay = new kakao.maps.CustomOverlay({ zIndex: 1 }); |
107 | -</div> | 143 | + var contentNode = document.createElement("div"); |
108 | - | 144 | + var markers = []; |
109 | -<div id="map" style="width: 100%; height: 575px"></div> | 145 | + var currCategory = "CE7"; // 카테고리코드: 카페 |
110 | -<script | 146 | + var order = 1; |
111 | - type="text/javascript" | 147 | + var mapContainer = document.getElementById("map"), |
112 | - src="//dapi.kakao.com/v2/maps/sdk.js?appkey=68cbccbcd6f0fef0a213e62ad37393ee&libraries=services" | 148 | + mapOption = { |
113 | -></script> | 149 | + center: new kakao.maps.LatLng(36.2477502, 127.078164), |
114 | -<script> | 150 | + level: 3, |
115 | - var lat = ""; | 151 | + }; |
116 | - var lon = ""; | 152 | + var map = new kakao.maps.Map(mapContainer, mapOption); |
117 | - var placeOverlay = new kakao.maps.CustomOverlay({ zIndex: 1 }); | 153 | + var ps = new kakao.maps.services.Places(map); |
118 | - var contentNode = document.createElement("div"); | 154 | + kakao.maps.event.addListener(map, "idle", searchPlaces); |
119 | - var markers = []; | 155 | + contentNode.className = "placeinfo_wrap"; |
120 | - var currCategory = "CE7"; // 카테고리코드: 카페 | 156 | + addEventHandle(contentNode, "mousedown", kakao.maps.event.preventMap); |
121 | - var order = 1; | 157 | + addEventHandle(contentNode, "touchstart", kakao.maps.event.preventMap); |
122 | - var mapContainer = document.getElementById("map"), | 158 | + placeOverlay.setContent(contentNode); |
123 | - mapOption = { | 159 | + function addEventHandle(target, type, callback) { |
124 | - center: new kakao.maps.LatLng(36.2477502, 127.078164), | 160 | + if (target.addEventListener) { |
125 | - level: 3, | 161 | + target.addEventListener(type, callback); |
126 | - }; | 162 | + } else { |
127 | - var map = new kakao.maps.Map(mapContainer, mapOption); | 163 | + target.attachEvent("on" + type, callback); |
128 | - var ps = new kakao.maps.services.Places(map); | 164 | + } |
129 | - kakao.maps.event.addListener(map, "idle", searchPlaces); | 165 | + } |
130 | - contentNode.className = "placeinfo_wrap"; | 166 | + placeOverlay.setContent(contentNode); |
131 | - addEventHandle(contentNode, "mousedown", kakao.maps.event.preventMap); | 167 | + if (navigator.geolocation) { |
132 | - addEventHandle(contentNode, "touchstart", kakao.maps.event.preventMap); | 168 | + navigator.geolocation.getCurrentPosition(function (position) { |
133 | - placeOverlay.setContent(contentNode); | 169 | + lat = position.coords.latitude; |
134 | - function addEventHandle(target, type, callback) { | 170 | + lon = position.coords.longitude; |
135 | - if (target.addEventListener) { | 171 | + var locPosition = new kakao.maps.LatLng(lat, lon); |
136 | - target.addEventListener(type, callback); | 172 | + displayCurrentPosition(locPosition); |
137 | - } else { | ||
138 | - target.attachEvent("on" + type, callback); | ||
139 | - } | ||
140 | - } | ||
141 | - placeOverlay.setContent(contentNode); | ||
142 | - if (navigator.geolocation) { | ||
143 | - navigator.geolocation.getCurrentPosition(function (position) { | ||
144 | - lat = position.coords.latitude; | ||
145 | - lon = position.coords.longitude; | ||
146 | - var locPosition = new kakao.maps.LatLng(lat, lon); | ||
147 | - displayCurrentPosition(locPosition); | ||
148 | - }); | ||
149 | - } else { | ||
150 | - var locPosition = new kakao.maps.LatLng(36.2477502, 127.078164); | ||
151 | - displayCurrentPosition(locPosition); | ||
152 | - } | ||
153 | - function displayCurrentPosition(locPosition) { | ||
154 | - map.setCenter(locPosition); | ||
155 | - } | ||
156 | - kakao.maps.event.addListener(map, "idle", searchPlaces); | ||
157 | - function searchPlaces() { | ||
158 | - if (!currCategory) { | ||
159 | - return; | ||
160 | - } | ||
161 | - placeOverlay.setMap(null); | ||
162 | - ps.categorySearch(currCategory, placesSearchCB, { usemapBounds: true }); | ||
163 | - } | ||
164 | - function placesSearchCB(data, status, pagination) { | ||
165 | - if (status === kakao.maps.services.Status.OK) { | ||
166 | - displayPlaces(data); | ||
167 | - } | ||
168 | - } | ||
169 | - function displayPlaces(places) { | ||
170 | - for (var i = 0; i < places.length; i++) { | ||
171 | - var marker = addMarker( | ||
172 | - new kakao.maps.LatLng(places[i].y, places[i].x), | ||
173 | - order | ||
174 | - ); | ||
175 | - (function (marker, place) { | ||
176 | - kakao.maps.event.addListener(marker, "click", function () { | ||
177 | - displayPlaceInfo(place); | ||
178 | }); | 173 | }); |
179 | - })(marker, places[i]); | 174 | + } else { |
180 | - } | 175 | + var locPosition = new kakao.maps.LatLng(36.2477502, 127.078164); |
181 | - } | 176 | + displayCurrentPosition(locPosition); |
182 | - function addMarker(position, order) { | 177 | + } |
183 | - var imageSrc = | 178 | + function displayCurrentPosition(locPosition) { |
184 | - "https://t1.daumcdn.net/localimg/localimages/07/mapapidoc/places_category.png"; | 179 | + map.setCenter(locPosition); |
185 | - var imageSize = new kakao.maps.Size(27, 30); | 180 | + } |
186 | - var imgOptions = { | 181 | + kakao.maps.event.addListener(map, "idle", searchPlaces); |
187 | - spriteSize: new kakao.maps.Size(72, 220), | 182 | + function searchPlaces() { |
188 | - spriteOrigin: new kakao.maps.Point(46, 150), | 183 | + if (!currCategory) { |
189 | - offset: new kakao.maps.Point(11, 28), | 184 | + return; |
190 | - }; | 185 | + } |
191 | - var markerImage = new kakao.maps.MarkerImage( | 186 | + placeOverlay.setMap(null); |
192 | - imageSrc, | 187 | + ps.categorySearch(currCategory, placesSearchCB, { usemapBounds: true }); |
193 | - imageSize, | 188 | + } |
194 | - imgOptions | 189 | + function placesSearchCB(data, status, pagination) { |
195 | - ); | 190 | + if (status === kakao.maps.services.Status.OK) { |
196 | - var marker = new kakao.maps.Marker({ | 191 | + displayPlaces(data); |
197 | - position: position, | 192 | + } |
198 | - image: markerImage, | 193 | + } |
199 | - }); | 194 | + function displayPlaces(places) { |
200 | - marker.setMap(map); | 195 | + for (var i = 0; i < places.length; i++) { |
201 | - markers.push(marker); | 196 | + var marker = addMarker( |
202 | - return marker; | 197 | + new kakao.maps.LatLng(places[i].y, places[i].x), |
203 | - } | 198 | + order |
204 | - function displayPlaceInfo(place) { | 199 | + ); |
205 | - var content = | 200 | + (function (marker, place) { |
206 | - '<div class="placeinfo">' + | 201 | + kakao.maps.event.addListener(marker, "click", function () { |
207 | - ' <a class="title" href="' + | 202 | + displayPlaceInfo(place); |
208 | - place.place_url + | 203 | + }); |
209 | - '" target="_blank" title="' + | 204 | + })(marker, places[i]); |
210 | - place.place_name + | 205 | + } |
206 | + } | ||
207 | + function addMarker(position, order) { | ||
208 | + var imageSrc = | ||
209 | + "https://t1.daumcdn.net/localimg/localimages/07/mapapidoc/places_category.png"; | ||
210 | + var imageSize = new kakao.maps.Size(27, 30); | ||
211 | + var imgOptions = { | ||
212 | + spriteSize: new kakao.maps.Size(72, 220), | ||
213 | + spriteOrigin: new kakao.maps.Point(46, 150), | ||
214 | + offset: new kakao.maps.Point(11, 28), | ||
215 | + }; | ||
216 | + var markerImage = new kakao.maps.MarkerImage( | ||
217 | + imageSrc, | ||
218 | + imageSize, | ||
219 | + imgOptions | ||
220 | + ); | ||
221 | + var marker = new kakao.maps.Marker({ | ||
222 | + position: position, | ||
223 | + image: markerImage, | ||
224 | + }); | ||
225 | + marker.setMap(map); | ||
226 | + markers.push(marker); | ||
227 | + return marker; | ||
228 | + } | ||
229 | + function displayPlaceInfo(place) { | ||
230 | + var content = | ||
231 | + '<div class="placeinfo">' + | ||
232 | + ' <a class="title" href="' + | ||
233 | + place.place_url + | ||
234 | + '" target="_blank" title="' + | ||
235 | + place.place_name + | ||
236 | + '">' + | ||
237 | + place.place_name + | ||
238 | + "</a>"; | ||
239 | + if (place.road_address_name) { | ||
240 | + content += | ||
241 | + ' <span title="' + | ||
242 | + place.road_address_name + | ||
211 | '">' + | 243 | '">' + |
212 | - place.place_name + | 244 | + place.road_address_name + |
213 | - "</a>"; | ||
214 | - if (place.road_address_name) { | ||
215 | - content += | ||
216 | - ' <span title="' + | ||
217 | - place.road_address_name + | ||
218 | - '">' + | ||
219 | - place.road_address_name + | ||
220 | - "</span>" + | ||
221 | - ' <span class="jibun" title="' + | ||
222 | - place.address_name + | ||
223 | - '">(지번 : ' + | ||
224 | - place.address_name + | ||
225 | - ")</span>"; | ||
226 | - } else { | ||
227 | - content += | ||
228 | - ' <span title="' + | ||
229 | - place.address_name + | ||
230 | - '">' + | ||
231 | - place.address_name + | ||
232 | - "</span>"; | ||
233 | - } | ||
234 | - content += | ||
235 | - ' <span class="tel">' + | ||
236 | - place.phone + | ||
237 | "</span>" + | 245 | "</span>" + |
238 | - "</div>" + | 246 | + ' <span class="jibun" title="' + |
239 | - '<div class="after"></div>'; | 247 | + place.address_name + |
240 | - contentNode.innerHTML = content; | 248 | + '">(지번 : ' + |
241 | - placeOverlay.setPosition(new kakao.maps.LatLng(place.y, place.x)); | 249 | + place.address_name + |
242 | - placeOverlay.setMap(map); | 250 | + ")</span>"; |
243 | - } | 251 | + } else { |
244 | -</script> | 252 | + content += |
245 | -<script src="javascripts/bootstrap.js"></script> | 253 | + ' <span title="' + |
246 | -<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> | 254 | + place.address_name + |
247 | -</body> | 255 | + '">' + |
256 | + place.address_name + | ||
257 | + "</span>"; | ||
258 | + } | ||
259 | + content += | ||
260 | + ' <span class="tel">' + | ||
261 | + place.phone + | ||
262 | + "</span>" + | ||
263 | + "</div>" + | ||
264 | + '<div class="after"></div>'; | ||
265 | + contentNode.innerHTML = content; | ||
266 | + placeOverlay.setPosition(new kakao.maps.LatLng(place.y, place.x)); | ||
267 | + placeOverlay.setMap(map); | ||
268 | + } | ||
269 | + </script> | ||
270 | + <script src="javascripts/bootstrap.js"></script> | ||
271 | + <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> | ||
272 | + </body> | ||
248 | </html> | 273 | </html> | ... | ... |
-
Please register or login to post a comment