-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdorong.html
More file actions
274 lines (254 loc) · 8.37 KB
/
dorong.html
File metadata and controls
274 lines (254 loc) · 8.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>카카오 주소 검색 및 좌표 변환</title>
<script src="//t1.daumcdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js"></script>
<script src="//dapi.kakao.com/v2/maps/sdk.js?appkey=076e534c41e81d0280f67bca54ac8d8c&libraries=services"></script>
<style>
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
max-width: 800px;
margin: 50px auto;
padding: 20px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
}
.container {
background: white;
padding: 30px;
border-radius: 15px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}
h1 {
color: #333;
text-align: center;
margin-bottom: 30px;
}
.search-box {
display: flex;
gap: 10px;
margin-bottom: 30px;
}
input[type="text"] {
flex: 1;
padding: 12px;
border: 2px solid #ddd;
border-radius: 8px;
font-size: 16px;
transition: border-color 0.3s;
}
input[type="text"]:focus {
outline: none;
border-color: #667eea;
}
button {
padding: 12px 24px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 8px;
font-size: 16px;
cursor: pointer;
transition: transform 0.2s;
}
button:hover {
transform: translateY(-2px);
}
button:active {
transform: translateY(0);
}
.result-box {
background: #f8f9fa;
padding: 20px;
border-radius: 10px;
margin-top: 20px;
display: none;
}
.result-box.show {
display: block;
animation: fadeIn 0.5s;
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(-10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.info-item {
margin: 10px 0;
padding: 10px;
background: white;
border-radius: 5px;
border-left: 4px solid #667eea;
}
.label {
font-weight: bold;
color: #667eea;
display: inline-block;
width: 120px;
}
.value {
color: #333;
}
.notice {
background: #fff3cd;
padding: 15px;
border-radius: 8px;
margin-bottom: 20px;
border-left: 4px solid #ffc107;
}
#map {
width: 100%;
height: 300px;
border-radius: 10px;
margin-top: 20px;
display: none;
}
#map.show {
display: block;
}
</style>
</head>
<body>
<div class="container">
<h1>🗺️ 카카오 주소 검색 및 좌표 변환</h1>
<div class="notice">
<strong>✅ API 키 설정 완료:</strong> 카카오 Maps API 키가 정상적으로
설정되었습니다. 이제 주소 검색과 좌표 변환 기능을 사용할 수 있습니다.
</div>
<div class="search-box">
<input
type="text"
id="address"
placeholder="주소를 입력하거나 검색 버튼을 클릭하세요"
readonly
/>
<button onclick="execDaumPostcode()">주소 검색</button>
</div>
<div id="result" class="result-box">
<h3>📍 주소 정보</h3>
<div class="info-item">
<span class="label">우편번호:</span>
<span class="value" id="zonecode">-</span>
</div>
<div class="info-item">
<span class="label">도로명 주소:</span>
<span class="value" id="roadAddress">-</span>
</div>
<div class="info-item">
<span class="label">지번 주소:</span>
<span class="value" id="jibunAddress">-</span>
</div>
<h3 style="margin-top: 20px">🌐 좌표 정보</h3>
<div class="info-item">
<span class="label">위도 (Latitude):</span>
<span class="value" id="latitude">-</span>
</div>
<div class="info-item">
<span class="label">경도 (Longitude):</span>
<span class="value" id="longitude">-</span>
</div>
</div>
<div id="map"></div>
</div>
<script>
// API 로딩 완료 확인
function waitForKakaoAPI(callback) {
if (typeof kakao !== "undefined" && kakao.maps && kakao.maps.services) {
callback();
} else {
setTimeout(() => waitForKakaoAPI(callback), 100);
}
}
// 카카오 우편번호 서비스 실행
function execDaumPostcode() {
new daum.Postcode({
oncomplete: function (data) {
// 선택한 주소 정보 표시
document.getElementById("address").value = data.address;
document.getElementById("zonecode").textContent = data.zonecode;
document.getElementById("roadAddress").textContent =
data.roadAddress || "-";
document.getElementById("jibunAddress").textContent =
data.jibunAddress || data.autoJibunAddress || "-";
// 결과 박스 표시
document.getElementById("result").classList.add("show");
// 주소로 좌표 변환 (API 로딩 대기)
waitForKakaoAPI(() => getCoordinates(data.address));
},
}).open();
}
// 주소를 좌표로 변환
function getCoordinates(address) {
// 디버깅 정보 출력
console.log("kakao 객체:", typeof kakao);
console.log("kakao.maps:", kakao && kakao.maps);
console.log(
"kakao.maps.services:",
kakao && kakao.maps && kakao.maps.services
);
// 카카오 Maps API가 로드되었는지 확인
if (
typeof kakao === "undefined" ||
!kakao.maps ||
!kakao.maps.services
) {
let errorMsg = "카카오 Maps API 로딩 실패\n\n";
if (typeof kakao === "undefined") {
errorMsg += "• kakao 객체가 정의되지 않음\n";
errorMsg += "• API 키가 유효하지 않거나 도메인이 등록되지 않음\n";
errorMsg += "• 네트워크 연결을 확인하세요\n\n";
errorMsg += "해결 방법:\n";
errorMsg += "1. 카카오 개발자 센터에서 플랫폼 설정 확인\n";
errorMsg +=
"2. 현재 도메인(localhost 또는 파일 경로)이 등록되어 있는지 확인\n";
errorMsg += "3. API 키가 활성화되어 있는지 확인";
} else if (!kakao.maps) {
errorMsg += "• kakao.maps 객체가 로드되지 않음";
} else if (!kakao.maps.services) {
errorMsg += "• services 라이브러리가 로드되지 않음";
}
alert(errorMsg);
document.getElementById("latitude").textContent = "API 로딩 실패";
document.getElementById("longitude").textContent = "API 로딩 실패";
return;
}
const geocoder = new kakao.maps.services.Geocoder();
geocoder.addressSearch(address, function (result, status) {
if (status === kakao.maps.services.Status.OK) {
const coords = new kakao.maps.LatLng(result[0].y, result[0].x);
// 좌표 표시
document.getElementById("latitude").textContent = result[0].y;
document.getElementById("longitude").textContent = result[0].x;
// 지도 표시
displayMap(coords);
} else {
document.getElementById("latitude").textContent = "변환 실패";
document.getElementById("longitude").textContent = "변환 실패";
}
});
}
// 지도 표시
function displayMap(coords) {
const mapContainer = document.getElementById("map");
mapContainer.classList.add("show");
const mapOption = {
center: coords,
level: 3,
};
const map = new kakao.maps.Map(mapContainer, mapOption);
// 마커 표시
const marker = new kakao.maps.Marker({
position: coords,
});
marker.setMap(map);
}
</script>
</body>
</html>