750 lines
23 KiB
HTML
750 lines
23 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="ko">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>네이버 플레이스 검색</title>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
|
|
min-height: 100vh;
|
|
color: #fff;
|
|
}
|
|
|
|
.container {
|
|
max-width: 800px;
|
|
margin: 0 auto;
|
|
padding: 40px 20px;
|
|
}
|
|
|
|
.header {
|
|
text-align: center;
|
|
margin-bottom: 40px;
|
|
}
|
|
|
|
.header h1 {
|
|
font-size: 2.5rem;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
-webkit-background-clip: text;
|
|
-webkit-text-fill-color: transparent;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.header p {
|
|
color: #a0aec0;
|
|
font-size: 1.1rem;
|
|
}
|
|
|
|
.search-box {
|
|
background: rgba(255, 255, 255, 0.1);
|
|
backdrop-filter: blur(10px);
|
|
border-radius: 16px;
|
|
padding: 30px;
|
|
margin-bottom: 30px;
|
|
}
|
|
|
|
.search-input-wrapper {
|
|
display: flex;
|
|
gap: 12px;
|
|
position: relative;
|
|
}
|
|
|
|
.search-input-container {
|
|
flex: 1;
|
|
position: relative;
|
|
}
|
|
|
|
.search-input {
|
|
width: 100%;
|
|
padding: 16px 20px;
|
|
font-size: 1.1rem;
|
|
border: 2px solid rgba(255, 255, 255, 0.2);
|
|
border-radius: 12px;
|
|
background: rgba(255, 255, 255, 0.05);
|
|
color: #fff;
|
|
outline: none;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.search-input:focus {
|
|
border-color: #667eea;
|
|
background: rgba(255, 255, 255, 0.1);
|
|
}
|
|
|
|
.search-input::placeholder {
|
|
color: #718096;
|
|
}
|
|
|
|
/* 자동완성 드롭다운 스타일 */
|
|
.autocomplete-dropdown {
|
|
position: absolute;
|
|
top: 100%;
|
|
left: 0;
|
|
right: 0;
|
|
background: rgba(30, 30, 50, 0.98);
|
|
border: 2px solid rgba(102, 126, 234, 0.5);
|
|
border-top: none;
|
|
border-radius: 0 0 12px 12px;
|
|
max-height: 300px;
|
|
overflow-y: auto;
|
|
z-index: 1000;
|
|
display: none;
|
|
}
|
|
|
|
.autocomplete-dropdown.active {
|
|
display: block;
|
|
}
|
|
|
|
.autocomplete-item {
|
|
padding: 12px 16px;
|
|
cursor: pointer;
|
|
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
|
transition: background 0.2s ease;
|
|
}
|
|
|
|
.autocomplete-item:last-child {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.autocomplete-item:hover {
|
|
background: rgba(102, 126, 234, 0.2);
|
|
}
|
|
|
|
.autocomplete-item.selected {
|
|
background: rgba(102, 126, 234, 0.3);
|
|
}
|
|
|
|
.autocomplete-title {
|
|
font-size: 1rem;
|
|
font-weight: 500;
|
|
color: #fff;
|
|
margin-bottom: 4px;
|
|
}
|
|
|
|
.autocomplete-meta {
|
|
font-size: 0.85rem;
|
|
color: #a0aec0;
|
|
}
|
|
|
|
.autocomplete-loading {
|
|
padding: 16px;
|
|
text-align: center;
|
|
color: #a0aec0;
|
|
}
|
|
|
|
.autocomplete-loading .mini-spinner {
|
|
display: inline-block;
|
|
width: 16px;
|
|
height: 16px;
|
|
border: 2px solid rgba(255, 255, 255, 0.1);
|
|
border-top-color: #667eea;
|
|
border-radius: 50%;
|
|
animation: spin 0.8s linear infinite;
|
|
margin-right: 8px;
|
|
vertical-align: middle;
|
|
}
|
|
|
|
.search-btn {
|
|
padding: 16px 32px;
|
|
font-size: 1.1rem;
|
|
font-weight: 600;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: #fff;
|
|
border: none;
|
|
border-radius: 12px;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.search-btn:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 10px 30px rgba(102, 126, 234, 0.4);
|
|
}
|
|
|
|
.search-btn:disabled {
|
|
opacity: 0.6;
|
|
cursor: not-allowed;
|
|
transform: none;
|
|
}
|
|
|
|
.loading {
|
|
text-align: center;
|
|
padding: 40px;
|
|
display: none;
|
|
}
|
|
|
|
.loading.active {
|
|
display: block;
|
|
}
|
|
|
|
.spinner {
|
|
width: 50px;
|
|
height: 50px;
|
|
border: 4px solid rgba(255, 255, 255, 0.1);
|
|
border-top-color: #667eea;
|
|
border-radius: 50%;
|
|
animation: spin 1s linear infinite;
|
|
margin: 0 auto 20px;
|
|
}
|
|
|
|
@keyframes spin {
|
|
to { transform: rotate(360deg); }
|
|
}
|
|
|
|
.results {
|
|
display: none;
|
|
}
|
|
|
|
.results.active {
|
|
display: block;
|
|
}
|
|
|
|
.result-item {
|
|
background: rgba(255, 255, 255, 0.1);
|
|
backdrop-filter: blur(10px);
|
|
border-radius: 16px;
|
|
padding: 24px;
|
|
margin-bottom: 16px;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
border: 2px solid transparent;
|
|
}
|
|
|
|
.result-item:hover {
|
|
background: rgba(255, 255, 255, 0.15);
|
|
border-color: #667eea;
|
|
transform: translateX(8px);
|
|
}
|
|
|
|
.result-header {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
margin-bottom: 12px;
|
|
}
|
|
|
|
.result-title {
|
|
font-size: 1.3rem;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.result-badge {
|
|
padding: 4px 12px;
|
|
background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
|
|
border-radius: 20px;
|
|
font-size: 0.85rem;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.result-badge.accommodation {
|
|
background: linear-gradient(135deg, #ed8936 0%, #dd6b20 100%);
|
|
}
|
|
|
|
.result-category {
|
|
color: #a0aec0;
|
|
font-size: 0.95rem;
|
|
margin-bottom: 8px;
|
|
}
|
|
|
|
.result-address {
|
|
color: #718096;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.result-place-id {
|
|
color: #667eea;
|
|
font-size: 0.85rem;
|
|
margin-top: 8px;
|
|
font-family: monospace;
|
|
}
|
|
|
|
.no-results {
|
|
text-align: center;
|
|
padding: 40px;
|
|
color: #a0aec0;
|
|
}
|
|
|
|
.error-message {
|
|
background: rgba(239, 68, 68, 0.2);
|
|
border: 1px solid rgba(239, 68, 68, 0.5);
|
|
border-radius: 12px;
|
|
padding: 16px;
|
|
color: #fca5a5;
|
|
margin-top: 20px;
|
|
display: none;
|
|
}
|
|
|
|
.error-message.active {
|
|
display: block;
|
|
}
|
|
|
|
.info-text {
|
|
text-align: center;
|
|
color: #718096;
|
|
font-size: 0.9rem;
|
|
margin-top: 20px;
|
|
}
|
|
|
|
.log-section {
|
|
background: rgba(0, 0, 0, 0.3);
|
|
border-radius: 12px;
|
|
padding: 16px;
|
|
margin-top: 20px;
|
|
display: none;
|
|
}
|
|
|
|
.log-section.active {
|
|
display: block;
|
|
}
|
|
|
|
.log-header {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
margin-bottom: 12px;
|
|
}
|
|
|
|
.log-title {
|
|
font-size: 0.9rem;
|
|
color: #a0aec0;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
|
|
.log-toggle {
|
|
background: none;
|
|
border: none;
|
|
color: #667eea;
|
|
cursor: pointer;
|
|
font-size: 0.85rem;
|
|
}
|
|
|
|
.log-content {
|
|
background: rgba(0, 0, 0, 0.4);
|
|
border-radius: 8px;
|
|
padding: 12px;
|
|
font-family: 'Fira Code', monospace;
|
|
font-size: 0.8rem;
|
|
color: #68d391;
|
|
max-height: 200px;
|
|
overflow-y: auto;
|
|
}
|
|
|
|
.log-line {
|
|
margin-bottom: 4px;
|
|
padding: 2px 0;
|
|
}
|
|
|
|
.log-line.info {
|
|
color: #68d391;
|
|
}
|
|
|
|
.log-line.warn {
|
|
color: #fbd38d;
|
|
}
|
|
|
|
.log-line.error {
|
|
color: #fc8181;
|
|
}
|
|
|
|
.search-stats {
|
|
display: flex;
|
|
gap: 16px;
|
|
margin-bottom: 16px;
|
|
padding: 12px 16px;
|
|
background: rgba(102, 126, 234, 0.1);
|
|
border-radius: 10px;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.stat-item {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
color: #a0aec0;
|
|
}
|
|
|
|
.stat-value {
|
|
color: #667eea;
|
|
font-weight: 600;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="header">
|
|
<h1>네이버 플레이스 검색</h1>
|
|
<p>숙박/펜션 업체를 검색하고 상세 정보를 확인하세요</p>
|
|
</div>
|
|
|
|
<div class="search-box">
|
|
<div class="search-input-wrapper">
|
|
<div class="search-input-container">
|
|
<input
|
|
type="text"
|
|
class="search-input"
|
|
id="searchInput"
|
|
placeholder="업체명을 입력하세요 (예: 스테이 머뭄)"
|
|
oninput="handleInput(event)"
|
|
onkeydown="handleKeyDown(event)"
|
|
onfocus="showAutocomplete()"
|
|
autocomplete="off"
|
|
>
|
|
<div class="autocomplete-dropdown" id="autocompleteDropdown"></div>
|
|
</div>
|
|
<button class="search-btn" id="searchBtn" onclick="search()">검색</button>
|
|
</div>
|
|
<div class="error-message" id="errorMessage"></div>
|
|
</div>
|
|
|
|
<div class="loading" id="loading">
|
|
<div class="spinner"></div>
|
|
<p>검색 중입니다... (브라우저 검색은 5-7초 소요)</p>
|
|
</div>
|
|
|
|
<div class="results" id="results"></div>
|
|
|
|
<!-- 로그 섹션 -->
|
|
<div class="log-section" id="logSection">
|
|
<div class="log-header">
|
|
<span class="log-title">
|
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/>
|
|
<polyline points="14 2 14 8 20 8"/>
|
|
</svg>
|
|
검색 로그
|
|
</span>
|
|
<button class="log-toggle" onclick="toggleLog()">접기/펼치기</button>
|
|
</div>
|
|
<div class="log-content" id="logContent"></div>
|
|
</div>
|
|
|
|
<p class="info-text">
|
|
검색 결과에서 업체를 클릭하면 상세 정보 페이지로 이동합니다.
|
|
</p>
|
|
</div>
|
|
|
|
<script>
|
|
let logVisible = true;
|
|
let autocompleteTimeout = null;
|
|
let autocompleteResults = [];
|
|
let selectedIndex = -1;
|
|
|
|
// 자동완성 입력 처리
|
|
function handleInput(event) {
|
|
const query = event.target.value.trim();
|
|
|
|
// 이전 타임아웃 취소
|
|
if (autocompleteTimeout) {
|
|
clearTimeout(autocompleteTimeout);
|
|
}
|
|
|
|
if (query.length < 2) {
|
|
hideAutocomplete();
|
|
return;
|
|
}
|
|
|
|
// 300ms 디바운스
|
|
autocompleteTimeout = setTimeout(() => {
|
|
fetchAutocomplete(query);
|
|
}, 300);
|
|
}
|
|
|
|
// 키보드 네비게이션
|
|
function handleKeyDown(event) {
|
|
const dropdown = document.getElementById('autocompleteDropdown');
|
|
|
|
if (!dropdown.classList.contains('active')) {
|
|
if (event.key === 'Enter') {
|
|
search();
|
|
}
|
|
return;
|
|
}
|
|
|
|
const items = dropdown.querySelectorAll('.autocomplete-item');
|
|
|
|
switch(event.key) {
|
|
case 'ArrowDown':
|
|
event.preventDefault();
|
|
selectedIndex = Math.min(selectedIndex + 1, items.length - 1);
|
|
updateSelection(items);
|
|
break;
|
|
case 'ArrowUp':
|
|
event.preventDefault();
|
|
selectedIndex = Math.max(selectedIndex - 1, -1);
|
|
updateSelection(items);
|
|
break;
|
|
case 'Enter':
|
|
event.preventDefault();
|
|
if (selectedIndex >= 0 && autocompleteResults[selectedIndex]) {
|
|
selectAutocompleteItem(autocompleteResults[selectedIndex]);
|
|
} else {
|
|
hideAutocomplete();
|
|
search();
|
|
}
|
|
break;
|
|
case 'Escape':
|
|
hideAutocomplete();
|
|
break;
|
|
}
|
|
}
|
|
|
|
function updateSelection(items) {
|
|
items.forEach((item, index) => {
|
|
if (index === selectedIndex) {
|
|
item.classList.add('selected');
|
|
item.scrollIntoView({ block: 'nearest' });
|
|
} else {
|
|
item.classList.remove('selected');
|
|
}
|
|
});
|
|
}
|
|
|
|
// 자동완성 API 호출
|
|
async function fetchAutocomplete(query) {
|
|
const dropdown = document.getElementById('autocompleteDropdown');
|
|
|
|
// 로딩 표시
|
|
dropdown.innerHTML = '<div class="autocomplete-loading"><span class="mini-spinner"></span>검색 중...</div>';
|
|
dropdown.classList.add('active');
|
|
|
|
try {
|
|
const response = await fetch('/api/autocomplete', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ query })
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (data.results && data.results.length > 0) {
|
|
autocompleteResults = data.results;
|
|
selectedIndex = -1;
|
|
renderAutocomplete(data.results);
|
|
} else {
|
|
dropdown.innerHTML = '<div class="autocomplete-loading">검색 결과가 없습니다</div>';
|
|
}
|
|
} catch (error) {
|
|
dropdown.innerHTML = '<div class="autocomplete-loading">자동완성 오류</div>';
|
|
}
|
|
}
|
|
|
|
// 자동완성 결과 렌더링
|
|
function renderAutocomplete(results) {
|
|
const dropdown = document.getElementById('autocompleteDropdown');
|
|
|
|
let html = '';
|
|
results.forEach((item, index) => {
|
|
const category = item.category || '';
|
|
const address = item.address || '';
|
|
html += `
|
|
<div class="autocomplete-item" onclick="selectAutocompleteItem(autocompleteResults[${index}])">
|
|
<div class="autocomplete-title">${item.title}</div>
|
|
<div class="autocomplete-meta">${category}${category && address ? ' · ' : ''}${address}</div>
|
|
</div>
|
|
`;
|
|
});
|
|
|
|
dropdown.innerHTML = html;
|
|
}
|
|
|
|
// 자동완성 항목 선택
|
|
function selectAutocompleteItem(item) {
|
|
// 주소에서 시/군/구 정보만 추출하여 검색어에 추가
|
|
// 예: "전북 군산시 나운동" -> "군산"
|
|
let locationKeyword = '';
|
|
if (item.address) {
|
|
// 주소에서 시/군/구 추출 (예: 군산시, 대구광역시, 강남구 등)
|
|
const match = item.address.match(/([가-힣]+(?:시|군|구))/);
|
|
if (match) {
|
|
locationKeyword = match[1].replace(/시$|군$|구$/, ''); // 시/군/구 제거
|
|
}
|
|
}
|
|
|
|
// 검색어: "업체명 지역" 형식으로 구성
|
|
const searchQuery = locationKeyword ? `${item.title} ${locationKeyword}` : item.title;
|
|
document.getElementById('searchInput').value = searchQuery;
|
|
hideAutocomplete();
|
|
search(); // 바로 검색 실행
|
|
}
|
|
|
|
function showAutocomplete() {
|
|
const query = document.getElementById('searchInput').value.trim();
|
|
if (query.length >= 2 && autocompleteResults.length > 0) {
|
|
document.getElementById('autocompleteDropdown').classList.add('active');
|
|
}
|
|
}
|
|
|
|
function hideAutocomplete() {
|
|
document.getElementById('autocompleteDropdown').classList.remove('active');
|
|
selectedIndex = -1;
|
|
}
|
|
|
|
// 외부 클릭 시 자동완성 숨기기
|
|
document.addEventListener('click', function(event) {
|
|
const container = document.querySelector('.search-input-container');
|
|
if (!container.contains(event.target)) {
|
|
hideAutocomplete();
|
|
}
|
|
});
|
|
|
|
function toggleLog() {
|
|
const logContent = document.getElementById('logContent');
|
|
logVisible = !logVisible;
|
|
logContent.style.display = logVisible ? 'block' : 'none';
|
|
}
|
|
|
|
function displayLogs(logs) {
|
|
const logSection = document.getElementById('logSection');
|
|
const logContent = document.getElementById('logContent');
|
|
|
|
if (!logs || logs.length === 0) {
|
|
logSection.classList.remove('active');
|
|
return;
|
|
}
|
|
|
|
let html = '';
|
|
logs.forEach(log => {
|
|
let className = 'info';
|
|
if (log.includes('error') || log.includes('Error')) {
|
|
className = 'error';
|
|
} else if (log.includes('찾지 못함') || log.includes('시도')) {
|
|
className = 'warn';
|
|
}
|
|
html += `<div class="log-line ${className}">${log}</div>`;
|
|
});
|
|
|
|
logContent.innerHTML = html;
|
|
logSection.classList.add('active');
|
|
}
|
|
|
|
async function search() {
|
|
const query = document.getElementById('searchInput').value.trim();
|
|
const searchBtn = document.getElementById('searchBtn');
|
|
const loading = document.getElementById('loading');
|
|
const results = document.getElementById('results');
|
|
const errorMessage = document.getElementById('errorMessage');
|
|
const logSection = document.getElementById('logSection');
|
|
|
|
if (!query) {
|
|
showError('검색어를 입력해주세요.');
|
|
return;
|
|
}
|
|
|
|
// UI 상태 변경
|
|
searchBtn.disabled = true;
|
|
loading.classList.add('active');
|
|
results.classList.remove('active');
|
|
errorMessage.classList.remove('active');
|
|
logSection.classList.remove('active');
|
|
|
|
try {
|
|
const response = await fetch('/api/search', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({ query }),
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
// 로그 표시
|
|
displayLogs(data.logs);
|
|
|
|
if (data.error) {
|
|
showError(data.error);
|
|
return;
|
|
}
|
|
|
|
displayResults(data.results, data.query, data.count);
|
|
} catch (error) {
|
|
showError('검색 중 오류가 발생했습니다: ' + error.message);
|
|
} finally {
|
|
searchBtn.disabled = false;
|
|
loading.classList.remove('active');
|
|
}
|
|
}
|
|
|
|
function showError(message) {
|
|
const errorMessage = document.getElementById('errorMessage');
|
|
errorMessage.textContent = message;
|
|
errorMessage.classList.add('active');
|
|
}
|
|
|
|
function displayResults(items, query, count) {
|
|
const results = document.getElementById('results');
|
|
|
|
if (!items || items.length === 0) {
|
|
results.innerHTML = '<div class="no-results">검색 결과가 없습니다.</div>';
|
|
results.classList.add('active');
|
|
return;
|
|
}
|
|
|
|
// 통계 정보
|
|
const accommodationCount = items.filter(i => i.is_accommodation).length;
|
|
const withPlaceIdCount = items.filter(i => i.place_id).length;
|
|
|
|
let html = `
|
|
<div class="search-stats">
|
|
<div class="stat-item">
|
|
<span>검색어:</span>
|
|
<span class="stat-value">"${query}"</span>
|
|
</div>
|
|
<div class="stat-item">
|
|
<span>총 결과:</span>
|
|
<span class="stat-value">${count}개</span>
|
|
</div>
|
|
<div class="stat-item">
|
|
<span>숙박업체:</span>
|
|
<span class="stat-value">${accommodationCount}개</span>
|
|
</div>
|
|
<div class="stat-item">
|
|
<span>place_id 있음:</span>
|
|
<span class="stat-value">${withPlaceIdCount}개</span>
|
|
</div>
|
|
</div>
|
|
`;
|
|
|
|
items.forEach((item, index) => {
|
|
const isAccommodation = item.is_accommodation;
|
|
const badgeClass = isAccommodation ? 'accommodation' : '';
|
|
const badgeText = isAccommodation ? '숙박업체' : '일반';
|
|
const hasPlaceId = item.place_id ? '' : 'style="opacity: 0.6"';
|
|
|
|
html += `
|
|
<div class="result-item" onclick="selectPlace('${item.place_id}', '${encodeURIComponent(item.title)}')" ${hasPlaceId}>
|
|
<div class="result-header">
|
|
<span class="result-title">${item.title}</span>
|
|
<span class="result-badge ${badgeClass}">${badgeText}</span>
|
|
</div>
|
|
<div class="result-category">${item.category || '카테고리 없음'}</div>
|
|
<div class="result-address">${item.address || '주소 정보 없음'}</div>
|
|
<div class="result-place-id">place_id: ${item.place_id || '❌ 없음 (상세조회 불가)'}</div>
|
|
</div>
|
|
`;
|
|
});
|
|
|
|
results.innerHTML = html;
|
|
results.classList.add('active');
|
|
}
|
|
|
|
function selectPlace(placeId, title) {
|
|
if (!placeId) {
|
|
alert('place_id가 없어 상세 정보를 조회할 수 없습니다.');
|
|
return;
|
|
}
|
|
window.location.href = `/result?place_id=${placeId}&title=${title}`;
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|