최지우

Main page & 주변 장소 검색 기능 추가

## Subject
Kakao 지도 API를 이용한 여행 경로 추천 서비스
출발지와 도착지를 설정하면 사이 경로의 유명 관광지/음식점/카페 등을 카테고리 별로 반환
원하는 장소를 경유지로 추가하여 경로를 재검색
Kakao 지도 API를 이용한 여행 경로 추천 서비스
출발지와 도착지를 설정하면 사이 경로의 유명 관광지/음식점/카페 등을 카테고리 별로 반환
원하는 장소를 경유지로 추가하여 경로를 재검색
## How to build
### git clone
~$ git clone http://khuhub.khu.ac.kr/2014104158/oss_project.git
### npm
~$ npm install
~/oss_project$ npm install
### Kakao 지도 API
<https://apis.map.kakao.com/web/>
카카오계정을 통해 APP KEY를 발급받은 후 views/main.ejs, views/search.ejs의 아래 부분에 추가
src = "//dapi.kakao.com/v2/maps/sdk.js?appkey=APPKEY&libraries=services"
<https://apis.map.kakao.com/web/>
카카오계정을 통해 APP KEY를 발급받은 후 views/main.ejs, views/search.ejs, views/near.ejs의 아래 부분에 추가
src = "//dapi.kakao.com/v2/maps/sdk.js?appkey=발급받은 APP KEY 입력&libraries=services"
## How to use
- 메인 페이지 지도상에서 출발지와 도착지를 선택하고 검색버튼 클릭
- 검색된 페이지에서 이동 경로에 있는 카테고리 별 장소(관광명소, 숙박, 카페, 음식점)를 검색 가능
- 지도 상에 마커와 인포윈도우를 통해 결과를 출력
- 원하는 경유지를 선택하여 경로 재검색 가능
* 메인 페이지에서 '여행 경유지 추천' 서비스와 '주변 장소' 서비스 선택 가능
- '여행 경유지 추천' 서비스는 출발지와 도착지를 설정하고 검색된 페이지에서 이동 경로에 있는 카테고리 별 장소(관광명소, 숙박, 카페, 음식점)를 검색 가능
+ 지도 상에 마커와 인포윈도우를 통해 결과를 출력
+ 원하는 경유지를 선택하여 경로 재검색 가능
- '주변 장소 검색' 서비스는 현재 위치를 설정해주면 주변 카테고리 별 장소(관광명소, 숙박, 카페, 음식점, 마트, 은행)를 검색 가능
+ 지도 상에 마커와 인포윈도우를 통해 결과를 출력
+ 마커를 클릭하면 해당 장소의 정보 조회 가능
## License
MIT License
Copyright (c) 2020 Jiwoo Choi
Copyright (c) 2020 Jiwoo Choi
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
......
......@@ -4,8 +4,10 @@ var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var mainRouter = require('./routes/main');
var mainRouter = require('./routes/main')
var passRouter = require('./routes/pass');
var searchRouter = require('./routes/search')
var nearRouter = require('./routes/near')
var app = express();
// view engine setup
......@@ -19,7 +21,9 @@ app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', mainRouter);
app.use('/pass', passRouter);
app.use('/search', searchRouter);
app.use('/near', nearRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
......
var express = require('express');
var router = express.Router();
router.get('/', function(req, res, next) {
res.render('near', { title: 'MINE' });
});
module.exports = router;
var express = require('express');
var router = express.Router();
router.get('/', function(req, res, next) {
res.render('pass', { title: 'MINE' });
});
module.exports = router;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Pass-Path</title>
</head>
<body>
<div id="map" style="width:100%;height:800px;"></div>
<p>출발지와 도착지를 설정해주세요!</p>
<script type="text/javascript" src="//dapi.kakao.com/v2/maps/sdk.js?appkey=비밀"></script>
<script>
var mapContainer = document.getElementById('map'), // 지도를 표시할 div
mapOption = {
center: new kakao.maps.LatLng(37.564213, 127.001698),
level: 10 // 지도의 확대 레벨
};
var map = new kakao.maps.Map(mapContainer, mapOption); // 지도를 생성합니다
var startSrc = 'https://t1.daumcdn.net/localimg/localimages/07/mapapidoc/red_b.png', // 출발 마커이미지의 주소입니다
startSize = new kakao.maps.Size(50, 45), // 출발 마커이미지의 크기입니다
startOption = {
offset: new kakao.maps.Point(15, 43) // 출발 마커이미지에서 마커의 좌표에 일치시킬 좌표를 설정합니다 (기본값은 이미지의 가운데 아래입니다)
};
// 출발 마커 이미지를 생성합니다
var startImage = new kakao.maps.MarkerImage(startSrc, startSize, startOption);
var startDragSrc = 'https://t1.daumcdn.net/localimg/localimages/07/mapapidoc/red_drag.png', // 출발 마커의 드래그 이미지 주소입니다
startDragSize = new kakao.maps.Size(50, 64), // 출발 마커의 드래그 이미지 크기입니다
startDragOption = {
offset: new kakao.maps.Point(15, 54) // 출발 마커의 드래그 이미지에서 마커의 좌표에 일치시킬 좌표를 설정합니다 (기본값은 이미지의 가운데 아래입니다)
};
// 출발 마커의 드래그 이미지를 생성합니다
var startDragImage = new kakao.maps.MarkerImage(startDragSrc, startDragSize, startDragOption);
// 출발 마커가 표시될 위치입니다
var startPosition = new kakao.maps.LatLng(37.564213, 127.001698);
// 출발 마커를 생성합니다
var startMarker = new kakao.maps.Marker({
map: map, // 출발 마커가 지도 위에 표시되도록 설정합니다
position: startPosition,
draggable: true, // 출발 마커가 드래그 가능하도록 설정합니다
image: startImage // 출발 마커이미지를 설정합니다
});
// 출발 마커에 dragstart 이벤트를 등록합니다
kakao.maps.event.addListener(startMarker, 'dragstart', function() {
// 출발 마커의 드래그가 시작될 때 마커 이미지를 변경합니다
startMarker.setImage(startDragImage);
});
// 출발 마커에 dragend 이벤트를 등록합니다
kakao.maps.event.addListener(startMarker, 'dragend', function() {
// 출발 마커의 드래그가 종료될 때 마커 이미지를 원래 이미지로 변경합니다
startMarker.setImage(startImage);
});
var arriveSrc = 'https://t1.daumcdn.net/localimg/localimages/07/mapapidoc/blue_b.png', // 도착 마커이미지 주소입니다
arriveSize = new kakao.maps.Size(50, 45), // 도착 마커이미지의 크기입니다
arriveOption = {
offset: new kakao.maps.Point(15, 43) // 도착 마커이미지에서 마커의 좌표에 일치시킬 좌표를 설정합니다 (기본값은 이미지의 가운데 아래입니다)
};
// 도착 마커 이미지를 생성합니다
var arriveImage = new kakao.maps.MarkerImage(arriveSrc, arriveSize, arriveOption);
var arriveDragSrc = 'https://t1.daumcdn.net/localimg/localimages/07/mapapidoc/blue_drag.png', // 도착 마커의 드래그 이미지 주소입니다
arriveDragSize = new kakao.maps.Size(50, 64), // 도착 마커의 드래그 이미지 크기입니다
arriveDragOption = {
offset: new kakao.maps.Point(15, 54) // 도착 마커의 드래그 이미지에서 마커의 좌표에 일치시킬 좌표를 설정합니다 (기본값은 이미지의 가운데 아래입니다)
};
// 도착 마커의 드래그 이미지를 생성합니다
var arriveDragImage = new kakao.maps.MarkerImage(arriveDragSrc, arriveDragSize, arriveDragOption);
// 도착 마커가 표시될 위치입니다
var arrivePosition = new kakao.maps.LatLng(37.564213, 127.011698);
// 도착 마커를 생성합니다
var arriveMarker = new kakao.maps.Marker({
map: map, // 도착 마커가 지도 위에 표시되도록 설정합니다
position: arrivePosition,
draggable: true, // 도착 마커가 드래그 가능하도록 설정합니다
image: arriveImage // 도착 마커이미지를 설정합니다
});
// 도착 마커에 dragstart 이벤트를 등록합니다
kakao.maps.event.addListener(arriveMarker, 'dragstart', function() {
// 도착 마커의 드래그가 시작될 때 마커 이미지를 변경합니다
arriveMarker.setImage(arriveDragImage);
});
// 도착 마커에 dragend 이벤트를 등록합니다
kakao.maps.event.addListener(arriveMarker, 'dragend', function() {
// 도착 마커의 드래그가 종료될 때 마커 이미지를 원래 이미지로 변경합니다
arriveMarker.setImage(arriveImage);
});
<html lang="ko">
</script>
<button type="button" onclick="Search();">text</button>
<head>
<link rel="stylesheet" type="text/css" href="https://t1.daumcdn.net/tistory_admin/lib/lightbox/css/lightbox.min.css" /><link rel="stylesheet" type="text/css" href="https://t1.daumcdn.net/tistory_admin/assets/blog/tistory-4143aead47fb3d3c83016433af84643a03241408/blogs/style/content/font.css?_version_=tistory-4143aead47fb3d3c83016433af84643a03241408" /><link rel="stylesheet" type="text/css" href="https://t1.daumcdn.net/tistory_admin/assets/blog/tistory-4143aead47fb3d3c83016433af84643a03241408/blogs/style/content/content.css?_version_=tistory-4143aead47fb3d3c83016433af84643a03241408" /><!--[if lt IE 9]><script src="https://t1.daumcdn.net/tistory_admin/lib/jquery/jquery-1.12.4.min.js"></script><![endif]--><!--[if gte IE 9]>
<!--><script src="https://t1.daumcdn.net/tistory_admin/lib/jquery/jquery-3.2.1.min.js"></script><!--<![endif]-->
<script src="https://t1.daumcdn.net/tistory_admin/lib/lightbox/js/lightbox-plus-jquery.min.js"></script>
<script>
function Search(){
var startx = startMarker.getPosition().getLat();
var starty = startMarker.getPosition().getLng();
var endx = arriveMarker.getPosition().getLat();
var endy = arriveMarker.getPosition().getLng();
location.href ='/search?startx='+ startx +'&starty='+ starty +'&endx=' + endx + '&endy=' + endy;
}
lightbox.options.fadeDuration = 200;
lightbox.options.resizeDuration = 200;
lightbox.options.wrapAround = false;
lightbox.options.albumLabel = "%1 / %2";
</script>
</body>
</html>
\ No newline at end of file
<script type="application/ld+json">{"@context":"http:\/\/schema.org","@type":"WebSite","url":"\/","potentialAction":{"@type":"SearchAction","target":"\/search\/{search_term_string}","query-input":"required name=search_term_string"}}</script>
<!-- END STRUCTURED_DATA -->
<title>Pass-Path</title>
<meta name="title" content="PASS-PATH" />
<meta name="description" Content="여행 경로 리커맨더" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, minimum-scale=1.0, maximum-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
<link rel="stylesheet" href="https://t1.daumcdn.net/tistory_admin/static/font/AvenirLTStd/AvenirLTStd.css" />
<link rel="stylesheet" href="https://t1.daumcdn.net/tistory_admin/static/font/SpoqaHanSans/SpoqaHanSans.css" />
<link rel="stylesheet" href="https://t1.daumcdn.net/tistory_admin/static/font/icomoon/icomoon.css" />
<link rel="stylesheet" href="https://tistory3.daumcdn.net/tistory/0/xf_Portfolio/style.css" />
<link rel="stylesheet" href="https://tistory3.daumcdn.net/tistory/0/xf_Portfolio/images/slick.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<script src="https://tistory3.daumcdn.net/tistory/0/xf_Portfolio/images/slick.js"></script>
<script src="https://tistory3.daumcdn.net/tistory/0/xf_Portfolio/images/common.js"></script>
<script src="https://unpkg.com/vh-check/dist/vh-check.min.js"></script>
<script>
(function () {
// initialize the test
var test = vhCheck();
}());
</script>
<link rel="stylesheet" type="text/css" href="https://t1.daumcdn.net/tistory_admin/assets/blog/tistory-4143aead47fb3d3c83016433af84643a03241408/blogs/plugins/TistoryProfileLayer/style.css?_version_=tistory-4143aead47fb3d3c83016433af84643a03241408" />
<script type="text/javascript" src="https://t1.daumcdn.net/tistory_admin/assets/blog/tistory-4143aead47fb3d3c83016433af84643a03241408/blogs/plugins/TistoryProfileLayer/profile.js?_version_=tistory-4143aead47fb3d3c83016433af84643a03241408"></script>
<style type="text/css">
.another_category { border: 1px solid #E5E5E5; padding: 10px 10px 5px; margin:10px 0; clear: both; }
.another_category h4 { font-size: 12px !important; margin: 0 !important; border-bottom: 1px solid #E5E5E5 !important; padding: 2px 0 6px !important; }
.another_category h4 a { font-weight: bold !important; }
.another_category table { table-layout: fixed; border-collapse: collapse; width: 100% !important; margin-top: 10px !important; }
* html .another_category table { width: auto !important; }
*:first-child+html .another_category table { width: auto !important; }
.another_category th, .another_category td { padding: 0 0 4px !important; }
.another_category th { text-align: left; font-size: 12px !important; font-weight: normal; word-break: break-all; overflow: hidden; line-height: 1.5; }
.another_category td { text-align: right; width: 80px; font-size: 11px; }
.another_category th a { font-weight: normal; text-decoration: none; border: none !important; }
.another_category th a.current{ font-weight: bold; text-decoration: none !important; border-bottom: 1px solid !important; }
.another_category th span { font-weight: normal; text-decoration: none; font: 10px Tahoma, Sans-serif; border: none !important; }
.another_category_color_gray, .another_category_color_gray h4 { border-color: #E5E5E5 !important; }
.another_category_color_gray * { color: #909090 !important; }
.another_category_color_gray th a.current{border-color:#909090 !important;}
.another_category_color_gray h4, .another_category_color_gray h4 a { color: #737373 !important; }
.another_category_color_red, .another_category_color_red h4 { border-color: #F6D4D3 !important; }
.another_category_color_red * { color: #E86869 !important; }
.another_category_color_red th a.current{border-color:#E86869 !important;}
.another_category_color_red h4, .another_category_color_red h4 a { color: #ED0908 !important; }
.another_category_color_green, .another_category_color_green h4 { border-color: #CCE7C8 !important; }
.another_category_color_green * { color: #64C05B !important; }
.another_category_color_green th a.current{border-color:#64C05B !important;}
.another_category_color_green h4, .another_category_color_green h4 a { color: #3EA731 !important; }
.another_category_color_blue, .another_category_color_blue h4 { border-color: #C8DAF2 !important; }
.another_category_color_blue * { color: #477FD6 !important; }
.another_category_color_blue th a.current{border-color:#477FD6 !important;}
.another_category_color_blue h4, .another_category_color_blue h4 a { color: #1960CA !important; }
.another_category_color_violet, .another_category_color_violet h4 { border-color: #E1CEEC !important; }
.another_category_color_violet * { color:#9D64C5 !important; }
.another_category_color_violet th a.current{border-color:#9D64C5 !important;}
.another_category_color_violet h4, .another_category_color_violet h4 a { color: #7E2CB5 !important; }
</style>
</head>
<body id="tt-body-index" class="theme_blue">
<script type="text/javascript" src="https://t1.daumcdn.net/tistory_admin/assets/blog/tistory-4143aead47fb3d3c83016433af84643a03241408/blogs/script/owner.js?_version_=tistory-4143aead47fb3d3c83016433af84643a03241408"></script>
<script type="text/javascript" src="https://t1.daumcdn.net/tistory_admin/assets/blog/tistory-4143aead47fb3d3c83016433af84643a03241408/blogs/script/blog/common.js?_version_=tistory-4143aead47fb3d3c83016433af84643a03241408"></script>
<div style="margin:0; padding:0; border:none; background:none; float:none; clear:none; z-index:0"></div>
<!-- warp / 테마 변경시 theme_pink / theme_blue / theme_green / theme_gray-->
<div id="wrap">
<!-- box_header -->
<header class="box_header">
<h1 class="title_logo">
<a href="/" title="Pass-Path" class="link_logo">
Pass-Path
</a>
</h1>
</header>
<div id="container">
<main id="main">
<div class="area_cover">
<!-- type_featured -->
<div class="type_featured">
<div class="slide_item">
<div class="link_slide item-thumbnail" style="background-image:url('https://tistory4.daumcdn.net/tistory/1978677/skinCover/fcb080e7767a4941964dfee78420025e');">
<div class="text_slide thema_apply">
<strong>PASS-PATH</strong>
<p class="text">여행지와 가고 싶은 장소만 선택하면<br>
경로가 자동으로 완성되는<br>
쉽고 간편한 여행 경로 리커맨더</p>
<a href="/pass" class="link_detail">경유지</a><br>
<a href="/near" class="link_detail">현재지</a>
</div>
</div>
</div>
<div class="inner_main_slide">
</div>
</div>
<!-- // type_featured -->
</div>
</main>
</div>
<footer id="footer">
<div class="inner_footer">
<a href="" class="link_footer">ERASER</a>
</div>
<div>
<address>© 2020 Pass-Path. All rights reserved.</address>
</div>
</footer>
</div>
</html>
......
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>주변 검색</title>
<style>
body, html {height: 100%;}
.map_wrap, .map_wrap * {margin:0; padding:0;font-family:'Malgun Gothic',dotum,'돋움',sans-serif;font-size:12px;}
.map_wrap {position:relative;width:100%;height:100%;}
#category {position:absolute;top:10px;left:10px;border-radius: 5px; border:1px solid #909090;box-shadow: 0 1px 1px rgba(0, 0, 0, 0.4);background: #fff;overflow: hidden;z-index: 2;}
#category li {float:left;list-style: none;width:50px;px;border-right:1px solid #acacac;padding:6px 0;text-align: center; cursor: pointer;}
#category li.on {background: #eee;}
#category li:hover {background: #ffe6e6;border-left:1px solid #acacac;margin-left: -1px;}
#category li:last-child{margin-right:0;border-right:0;}
#category li span {display: block;margin:0 auto 3px;width:27px;height: 28px;}
#category li .category_bg {background:url(https://t1.daumcdn.net/localimg/localimages/07/mapapidoc/places_category.png) no-repeat;}
#category li .bank {background-position: -10px 0;}
#category li .mart {background-position: -10px -36px;}
#category li .pharmacy {background-position: -10px -72px;}
#category li .oil {background-position: -10px -108px;}
#category li .cafe {background-position: -10px -144px;}
#category li .store {background-position: -10px -180px;}
#category li.on .category_bg {background-position-x:-46px;}
.placeinfo_wrap {position:absolute;bottom:28px;left:-150px;width:300px;}
.placeinfo {position:relative;width:100%;border-radius:6px;border: 1px solid #ccc;border-bottom:2px solid #ddd;padding-bottom: 10px;background: #fff;}
.placeinfo:nth-of-type(n) {border:0; box-shadow:0px 1px 2px #888;}
.placeinfo_wrap .after {content:'';position:relative;margin-left:-12px;left:50%;width:22px;height:12px;background:url('https://t1.daumcdn.net/localimg/localimages/07/mapapidoc/vertex_white.png')}
.placeinfo a, .placeinfo a:hover, .placeinfo a:active{color:#fff;text-decoration: none;}
.placeinfo a, .placeinfo span {display: block;text-overflow: ellipsis;overflow: hidden;white-space: nowrap;}
.placeinfo span {margin:5px 5px 0 5px;cursor: default;font-size:13px;}
.placeinfo .title {font-weight: bold; font-size:14px;border-radius: 6px 6px 0 0;margin: -1px -1px 0 -1px;padding:10px; color: #fff;background: #d95050;background: #d95050 url(https://t1.daumcdn.net/localimg/localimages/07/mapapidoc/arrow_white.png) no-repeat right 14px center;}
.placeinfo .tel {color:#0f7833;}
.placeinfo .jibun {color:#999;font-size:11px;margin-top:0;}
</style>
</head>
<body>
<p style="margin-top:-12px">
</p>
<div class="map_wrap">
<div id="map" style="width:100%;height:100%;position:relative;overflow:hidden;"></div>
<ul id="category">
<li id="BK9" data-order="0">
<span class="category_bg bank"></span>
은행
</li>
<li id="MT1" data-order="1">
<span class="category_bg mart"></span>
마트
</li>
<li id="PM9" data-order="2">
<span class="category_bg pharmacy"></span>
약국
</li>
<li id="AT4" data-order="3">
<span class="category_bg oil"></span>
관광지
</li>
<li id="CE7" data-order="4">
<span class="category_bg cafe"></span>
카페
</li>
<li id="CS2" data-order="5">
<span class="category_bg store"></span>
편의점
</li>
</ul>
</div>
<script type="text/javascript" src="//dapi.kakao.com/v2/maps/sdk.js?appkey=비밀&libraries=services"></script>
<script>
// 마커를 클릭했을 때 해당 장소의 상세정보를 보여줄 커스텀오버레이입니다
var placeOverlay = new kakao.maps.CustomOverlay({zIndex:1}),
contentNode = document.createElement('div'), // 커스텀 오버레이의 컨텐츠 엘리먼트 입니다
markers = [], // 마커를 담을 배열입니다
currCategory = ''; // 현재 선택된 카테고리를 가지고 있을 변수입니다
var mapContainer = document.getElementById('map'), // 지도를 표시할 div
mapOption = {
center: new kakao.maps.LatLng(35.950000, 128.250000), // 지도의 중심좌표
level: 12 // 지도의 확대 레벨
};
// 지도를 생성합니다
var map = new kakao.maps.Map(mapContainer, mapOption);
var startSrc = 'https://t1.daumcdn.net/localimg/localimages/07/mapapidoc/red_b.png', // 출발 마커이미지의 주소입니다
startSize = new kakao.maps.Size(50, 45), // 출발 마커이미지의 크기입니다
startOption = {
offset: new kakao.maps.Point(15, 43) // 출발 마커이미지에서 마커의 좌표에 일치시킬 좌표를 설정합니다 (기본값은 이미지의 가운데 아래입니다)
};
// 출발 마커 이미지를 생성합니다
var startImage = new kakao.maps.MarkerImage(startSrc, startSize, startOption);
var startDragSrc = 'https://t1.daumcdn.net/localimg/localimages/07/mapapidoc/red_drag.png', // 출발 마커의 드래그 이미지 주소입니다
startDragSize = new kakao.maps.Size(50, 64), // 출발 마커의 드래그 이미지 크기입니다
startDragOption = {
offset: new kakao.maps.Point(15, 54) // 출발 마커의 드래그 이미지에서 마커의 좌표에 일치시킬 좌표를 설정합니다 (기본값은 이미지의 가운데 아래입니다)
};
// 출발 마커의 드래그 이미지를 생성합니다
var startDragImage = new kakao.maps.MarkerImage(startDragSrc, startDragSize, startDragOption);
// 출발 마커가 표시될 위치입니다
var startPosition = new kakao.maps.LatLng(37.245635, 127.179108);
// 출발 마커를 생성합니다
var startMarker = new kakao.maps.Marker({
map: map, // 출발 마커가 지도 위에 표시되도록 설정합니다
position: startPosition,
draggable: true, // 출발 마커가 드래그 가능하도록 설정합니다
image: startImage // 출발 마커이미지를 설정합니다
});
// 출발 마커에 dragstart 이벤트를 등록합니다
kakao.maps.event.addListener(startMarker, 'dragstart', function() {
// 출발 마커의 드래그가 시작될 때 마커 이미지를 변경합니다
startMarker.setImage(startDragImage);
});
// 출발 마커에 dragend 이벤트를 등록합니다
kakao.maps.event.addListener(startMarker, 'dragend', function() {
// 출발 마커의 드래그가 종료될 때 마커 이미지를 원래 이미지로 변경합니다
startMarker.setImage(startImage);
});
// 장소 검색 객체를 생성합니다
var ps = new kakao.maps.services.Places();
// 지도에 idle 이벤트를 등록합니다
kakao.maps.event.addListener(map, 'idle', searchPlaces);
// 커스텀 오버레이의 컨텐츠 노드에 css class를 추가합니다
contentNode.className = 'placeinfo_wrap';
// 커스텀 오버레이의 컨텐츠 노드에 mousedown, touchstart 이벤트가 발생했을때
// 지도 객체에 이벤트가 전달되지 않도록 이벤트 핸들러로 kakao.maps.event.preventMap 메소드를 등록합니다
addEventHandle(contentNode, 'mousedown', kakao.maps.event.preventMap);
addEventHandle(contentNode, 'touchstart', kakao.maps.event.preventMap);
// 커스텀 오버레이 컨텐츠를 설정합니다
placeOverlay.setContent(contentNode);
// 각 카테고리에 클릭 이벤트를 등록합니다
addCategoryClickEvent();
// 엘리먼트에 이벤트 핸들러를 등록하는 함수입니다
function addEventHandle(target, type, callback) {
if (target.addEventListener) {
target.addEventListener(type, callback);
} else {
target.attachEvent('on' + type, callback);
}
}
// 카테고리 검색을 요청하는 함수입니다
function searchPlaces() {
if (!currCategory) {
return;
}
var startx = startMarker.getPosition().getLat();
var starty = startMarker.getPosition().getLng();
// 커스텀 오버레이를 숨깁니다
placeOverlay.setMap(null);
// 지도에 표시되고 있는 마커를 제거합니다
removeMarker();
ps.categorySearch(currCategory, placesSearchCB, {location: new kakao.maps.LatLng(startx, starty)});
}
// 장소검색이 완료됐을 때 호출되는 콜백함수 입니다
function placesSearchCB(data, status, pagination) {
if (status === kakao.maps.services.Status.OK) {
// 정상적으로 검색이 완료됐으면 지도에 마커를 표출합니다
displayPlaces(data);
} else if (status === kakao.maps.services.Status.ZERO_RESULT) {
// 검색결과가 없는경우 해야할 처리가 있다면 이곳에 작성해 주세요
} else if (status === kakao.maps.services.Status.ERROR) {
// 에러로 인해 검색결과가 나오지 않은 경우 해야할 처리가 있다면 이곳에 작성해 주세요
}
}
// 지도에 마커를 표출하는 함수입니다
function displayPlaces(places) {
// 몇번째 카테고리가 선택되어 있는지 얻어옵니다
// 이 순서는 스프라이트 이미지에서의 위치를 계산하는데 사용됩니다
var order = document.getElementById(currCategory).getAttribute('data-order');
for ( var i=0; i<places.length; i++ ) {
// 마커를 생성하고 지도에 표시합니다
var marker = addMarker(new kakao.maps.LatLng(places[i].y, places[i].x), order);
// 마커와 검색결과 항목을 클릭 했을 때
// 장소정보를 표출하도록 클릭 이벤트를 등록합니다
(function(marker, place) {
kakao.maps.event.addListener(marker, 'click', function() {
displayPlaceInfo(place);
});
})(marker, places[i]);
}
}
// 마커를 생성하고 지도 위에 마커를 표시하는 함수입니다
function addMarker(position, order) {
var imageSrc = 'https://t1.daumcdn.net/localimg/localimages/07/mapapidoc/places_category.png', // 마커 이미지 url, 스프라이트 이미지를 씁니다
imageSize = new kakao.maps.Size(27, 28), // 마커 이미지의 크기
imgOptions = {
spriteSize : new kakao.maps.Size(72, 208), // 스프라이트 이미지의 크기
spriteOrigin : new kakao.maps.Point(46, (order*36)), // 스프라이트 이미지 중 사용할 영역의 좌상단 좌표
offset: new kakao.maps.Point(11, 28) // 마커 좌표에 일치시킬 이미지 내에서의 좌표
},
markerImage = new kakao.maps.MarkerImage(imageSrc, imageSize, imgOptions),
marker = new kakao.maps.Marker({
position: position, // 마커의 위치
image: markerImage
});
marker.setMap(map); // 지도 위에 마커를 표출합니다
markers.push(marker); // 배열에 생성된 마커를 추가합니다
return marker;
}
// 지도 위에 표시되고 있는 마커를 모두 제거합니다
function removeMarker() {
for ( var i = 0; i < markers.length; i++ ) {
markers[i].setMap(null);
}
markers = [];
}
// 클릭한 마커에 대한 장소 상세정보를 커스텀 오버레이로 표시하는 함수입니다
function displayPlaceInfo (place) {
var content = '<div class="placeinfo">' +
' <a class="title" href="' + place.place_url + '" target="_blank" title="' + place.place_name + '">' + place.place_name + '</a>';
if (place.road_address_name) {
content += ' <span title="' + place.road_address_name + '">' + place.road_address_name + '</span>' +
' <span class="jibun" title="' + place.address_name + '">(지번 : ' + place.address_name + ')</span>';
} else {
content += ' <span title="' + place.address_name + '">' + place.address_name + '</span>';
}
content += ' <span class="tel">' + place.phone + '</span>' +
'</div>' +
'<div class="after"></div>';
contentNode.innerHTML = content;
placeOverlay.setPosition(new kakao.maps.LatLng(place.y, place.x));
placeOverlay.setMap(map);
}
// 각 카테고리에 클릭 이벤트를 등록합니다
function addCategoryClickEvent() {
var category = document.getElementById('category'),
children = category.children;
for (var i=0; i<children.length; i++) {
children[i].onclick = onClickCategory;
}
}
// 카테고리를 클릭했을 때 호출되는 함수입니다
function onClickCategory() {
var id = this.id,
className = this.className;
placeOverlay.setMap(null);
if (className === 'on') {
currCategory = '';
changeCategoryClass();
removeMarker();
} else {
currCategory = id;
changeCategoryClass(this);
searchPlaces();
}
}
// 클릭된 카테고리에만 클릭된 스타일을 적용하는 함수입니다
function changeCategoryClass(el) {
var category = document.getElementById('category'),
children = category.children,
i;
for ( i=0; i<children.length; i++ ) {
children[i].className = '';
}
if (el) {
el.className = 'on';
}
}
</script>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Pass-Path</title>
<style>body, html {height: 100%;}</style>
</head>
<body>
<p>출발지와 도착지를 설정해주세요!</p>
<button type="button" onclick="Search();">검색</button>
<script>
function Search(){
var startx = startMarker.getPosition().getLat();
var starty = startMarker.getPosition().getLng();
var endx = arriveMarker.getPosition().getLat();
var endy = arriveMarker.getPosition().getLng();
location.href ='/search?startx='+ startx +'&starty='+ starty +'&endx=' + endx + '&endy=' + endy;
}
</script>
<div id="map" style="width:100%;height:90%;"></div>
<script type="text/javascript" src="//dapi.kakao.com/v2/maps/sdk.js?appkey=비밀"></script>
<script>
var mapContainer = document.getElementById('map'), // 지도를 표시할 div
mapOption = {
center: new kakao.maps.LatLng(35.950000, 128.250000),
level: 12 // 지도의 확대 레벨
};
var map = new kakao.maps.Map(mapContainer, mapOption); // 지도를 생성합니다
var startSrc = 'https://t1.daumcdn.net/localimg/localimages/07/mapapidoc/red_b.png', // 출발 마커이미지의 주소입니다
startSize = new kakao.maps.Size(50, 45), // 출발 마커이미지의 크기입니다
startOption = {
offset: new kakao.maps.Point(15, 43) // 출발 마커이미지에서 마커의 좌표에 일치시킬 좌표를 설정합니다 (기본값은 이미지의 가운데 아래입니다)
};
// 출발 마커 이미지를 생성합니다
var startImage = new kakao.maps.MarkerImage(startSrc, startSize, startOption);
var startDragSrc = 'https://t1.daumcdn.net/localimg/localimages/07/mapapidoc/red_drag.png', // 출발 마커의 드래그 이미지 주소입니다
startDragSize = new kakao.maps.Size(50, 64), // 출발 마커의 드래그 이미지 크기입니다
startDragOption = {
offset: new kakao.maps.Point(15, 54) // 출발 마커의 드래그 이미지에서 마커의 좌표에 일치시킬 좌표를 설정합니다 (기본값은 이미지의 가운데 아래입니다)
};
// 출발 마커의 드래그 이미지를 생성합니다
var startDragImage = new kakao.maps.MarkerImage(startDragSrc, startDragSize, startDragOption);
// 출발 마커가 표시될 위치입니다
var startPosition = new kakao.maps.LatLng(37.571589, 126.975005);
// 출발 마커를 생성합니다
var startMarker = new kakao.maps.Marker({
map: map, // 출발 마커가 지도 위에 표시되도록 설정합니다
position: startPosition,
draggable: true, // 출발 마커가 드래그 가능하도록 설정합니다
image: startImage // 출발 마커이미지를 설정합니다
});
// 출발 마커에 dragstart 이벤트를 등록합니다
kakao.maps.event.addListener(startMarker, 'dragstart', function() {
// 출발 마커의 드래그가 시작될 때 마커 이미지를 변경합니다
startMarker.setImage(startDragImage);
});
// 출발 마커에 dragend 이벤트를 등록합니다
kakao.maps.event.addListener(startMarker, 'dragend', function() {
// 출발 마커의 드래그가 종료될 때 마커 이미지를 원래 이미지로 변경합니다
startMarker.setImage(startImage);
});
var arriveSrc = 'https://t1.daumcdn.net/localimg/localimages/07/mapapidoc/blue_b.png', // 도착 마커이미지 주소입니다
arriveSize = new kakao.maps.Size(50, 45), // 도착 마커이미지의 크기입니다
arriveOption = {
offset: new kakao.maps.Point(15, 43) // 도착 마커이미지에서 마커의 좌표에 일치시킬 좌표를 설정합니다 (기본값은 이미지의 가운데 아래입니다)
};
// 도착 마커 이미지를 생성합니다
var arriveImage = new kakao.maps.MarkerImage(arriveSrc, arriveSize, arriveOption);
var arriveDragSrc = 'https://t1.daumcdn.net/localimg/localimages/07/mapapidoc/blue_drag.png', // 도착 마커의 드래그 이미지 주소입니다
arriveDragSize = new kakao.maps.Size(50, 64), // 도착 마커의 드래그 이미지 크기입니다
arriveDragOption = {
offset: new kakao.maps.Point(15, 54) // 도착 마커의 드래그 이미지에서 마커의 좌표에 일치시킬 좌표를 설정합니다 (기본값은 이미지의 가운데 아래입니다)
};
// 도착 마커의 드래그 이미지를 생성합니다
var arriveDragImage = new kakao.maps.MarkerImage(arriveDragSrc, arriveDragSize, arriveDragOption);
// 도착 마커가 표시될 위치입니다
var arrivePosition = new kakao.maps.LatLng(37.280916, 127.102116);
// 도착 마커를 생성합니다
var arriveMarker = new kakao.maps.Marker({
map: map, // 도착 마커가 지도 위에 표시되도록 설정합니다
position: arrivePosition,
draggable: true, // 도착 마커가 드래그 가능하도록 설정합니다
image: arriveImage // 도착 마커이미지를 설정합니다
});
// 도착 마커에 dragstart 이벤트를 등록합니다
kakao.maps.event.addListener(arriveMarker, 'dragstart', function() {
// 도착 마커의 드래그가 시작될 때 마커 이미지를 변경합니다
arriveMarker.setImage(arriveDragImage);
});
// 도착 마커에 dragend 이벤트를 등록합니다
kakao.maps.event.addListener(arriveMarker, 'dragend', function() {
// 도착 마커의 드래그가 종료될 때 마커 이미지를 원래 이미지로 변경합니다
arriveMarker.setImage(arriveImage);
});
</script>
</body>
</html>
\ No newline at end of file
......@@ -4,8 +4,9 @@
<meta charset="utf-8">
<title>검색 결과</title>
<style>
body, html {height: 100%;}
.map_wrap, .map_wrap * {margin:0; padding:0;font-family:'Malgun Gothic',dotum,'돋움',sans-serif;font-size:12px;}
.map_wrap {position:relative;width:100%;height:800px;}
.map_wrap {position:relative;width:100%;height:100%;}
#category {position:absolute;top:10px;left:10px;border-radius: 5px; border:1px solid #909090;box-shadow: 0 1px 1px rgba(0, 0, 0, 0.4);background: #fff;overflow: hidden;z-index: 2;}
#category li {float:left;list-style: none;width:50px;px;border-right:1px solid #acacac;padding:6px 0;text-align: center; cursor: pointer;}
#category li.on {background: #eee;}
......@@ -67,7 +68,7 @@
<body>
<div class="map_wrap">
<div id="map" style="width:100%;height:800px;position:relative;overflow:hidden;"></div>
<div id="map" style="width:100%;height:100%;position:relative;overflow:hidden;"></div>
<ul id="category">
<li id="AT4" data-order="0">
<span class="category_bg oil"></span>
......@@ -128,7 +129,7 @@ var placeOverlay = new kakao.maps.CustomOverlay({zIndex:1}),
var mapContainer = document.getElementById('map'), // 지도를 표시할 div
mapOption = {
center: new kakao.maps.LatLng(endx, endy), // 지도의 중심좌표
level: 8 // 지도의 확대 레벨
level: 11 // 지도의 확대 레벨
};
// 지도를 생성합니다
......