<!-- direct-kakao.html -->
<!doctype html>
<html>
<head><meta charset="utf-8"><title>Kakao 직접 호출 (노출주의)</title></head>
<body>
<input id="addr" placeholder="주소 입력" style="width:60%">
<button id="btn">조회(직접)</button>
<div id="out"></div>
<script>
const KAKAO_API_KEY = "bb1b2ac193ac0040534e8560671067e7"; // 노출 위험!
document.getElementById("btn").addEventListener("click", async ()=>{
const address = document.getElementById("addr").value.trim();
if (!address) return alert("주소 입력");
try {
const url = new URL("https://dapi.kakao.com/v2/local/search/address.json");
url.searchParams.set("query", address);
const r = await fetch(url.toString(), {
headers: { "Authorization": `KakaoAK ${KAKAO_API_KEY}` }
});
const j = await r.json();
if (j.documents && j.documents.length) {
const d = j.documents[0];
document.getElementById("out").innerText = `${d.y},${d.x}`;
} else document.getElementById("out").innerText = "좌표 없음";
} catch (e) {
document.getElementById("out").innerText = "오류: " + e.message;
}
});
</script>
</body>
</html>
댓글 없음:
댓글 쓰기