๐Ÿ’ปCoding/๐ŸฆŠ Api

[Api] ์นด์นด์˜ค ์ฃผ์†Œ์ฐพ๊ธฐ api : kakao html input text api

์Œ์€์‘ 2022. 8. 31. 07:09
728x90
๋ฐ˜์‘ํ˜•
[Api] 
์นด์นด์˜ค ์ฃผ์†Œ์ฐพ๊ธฐ api 
: kakao html input text api
HTML / CSS / JS

 

โœ… ์ƒํ™ฉ
→ ํšŒ์›๊ฐ€์ž… ํผ์ด๋‚˜ ๋งˆ์ดํŽ˜์ด์ง€ ๋“ฑ ํšŒ์› ์ •๋ณด ๋“ฑ๋ก์—์„œ ํ”ํžˆ ๋ณผ ์ˆ˜ ์žˆ๋Š” ์ฃผ์†Œ ์ฐพ๊ธฐ ๊ธฐ๋Šฅ ๊ตฌํ˜„ํ•˜๊ณ  ์‹ถ์„ ๋•Œ

โœ… ๋ฐฉ๋ฒ•
์นด์นด์˜ค ์ฃผ์†Œ์ฐพ๊ธฐ Api ์‚ฌ์šฉ

โœ… ์‚ฌ์šฉ ๋ฐฉ๋ฒ•
→ HTML ์ž‘์„ฑ
→ CSS input ๋””์ž์ธ
→ JS ์—ฐ๋™ ๋ฐ ์„ ํƒ ์ž…๋ ฅ๊ฐ’ ์„ธํŒ…

 

 

๐ŸŸข ์•„๋ž˜์—์„œ ๊ธฐ๋ณธ ์‚ฌ์šฉ๋ฒ•์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

https://postcode.map.daum.net/guide

 

Daum ์šฐํŽธ๋ฒˆํ˜ธ ์„œ๋น„์Šค

์šฐํŽธ๋ฒˆํ˜ธ ๊ฒ€์ƒ‰๊ณผ ๋„๋กœ๋ช… ์ฃผ์†Œ ์ž…๋ ฅ ๊ธฐ๋Šฅ์„ ๋„ˆ๋ฌด ๊ฐ„๋‹จํ•˜๊ฒŒ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•. Daum ์šฐํŽธ๋ฒˆํ˜ธ ์„œ๋น„์Šค๋ฅผ ์ด์šฉํ•ด๋ณด์„ธ์š”. ์–ด๋Š ์‚ฌ์ดํŠธ์—์„œ๋‚˜ ๋ฌด๋ฃŒ๋กœ ์ œ์•ฝ์—†์ด ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ต๋‹ˆ๋‹ค.

postcode.map.daum.net

 

๐ŸŸ   ๊ธฐ๋ณธ ์‚ฌ์šฉ๋ฒ•

<script src="//t1.daumcdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js"></script>
<script>
    new daum.Postcode({
        oncomplete: function(data) {
            // ํŒ์—…์—์„œ ๊ฒ€์ƒ‰๊ฒฐ๊ณผ ํ•ญ๋ชฉ์„ ํด๋ฆญํ–ˆ์„๋•Œ ์‹คํ–‰ํ•  ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋Š” ๋ถ€๋ถ„์ž…๋‹ˆ๋‹ค.
            // ์˜ˆ์ œ๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ๋‹ค์–‘ํ•œ ํ™œ์šฉ๋ฒ•์„ ํ™•์ธํ•ด ๋ณด์„ธ์š”.
        }
    }).open();
</script>

 

๐Ÿ”ด ์•„๋ž˜ ์ฝ”๋“œ ์ ์šฉ์‹œ ์‹คํ–‰ ํ™”๋ฉด

 

๐ŸŸฃ ์ „์ฒด ์ฝ”๋“œ demo

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Kakao API</title>

    <!-- css, js ์—ฐ๊ฒฐ -->
    <link rel="stylesheet" href="../common/css/style.css">
    <script src="../common/js/joinForm.js"></script>
    <script src="//t1.daumcdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js"></script>

    <!-- css -->
    <style>
    .join_group {
    box-sizing: border-box;
    padding: 5px 0px 5px 0px;
    }
    .join_group > label {
        display: inline-block;
        box-sizing: border-box;
        width: 110px;
        margin: 0px 15px 0px 10px;
        font-size: 14px;
    }
    .join_group > input {
        box-sizing: border-box;
        width : 380px;
        height : 45px;
        padding : 5px 0px 0px 10px;
        margin: 0px 10px 0px 0px;
        border-radius: 5px;
        border: 1px solid #D9D9D9;
        font-size: 12px;
    }
    .join_group .btn_address {
        box-sizing: border-box;
        width : 380px;
        height : 45px;
        padding : 5px 0px 0px 10px;
        margin: 0px 10px 0px 0px;
        border-radius: 5px;
        border: 1px solid #D9D9D9;
        font-size: 13px;
        color : #a3a3a3;
        cursor: pointer;
    }
    .join_group > .detail_address {
        margin: 10px 0px 0px 140px;
        cursor: pointer;
    }
    </style>
</head>
<body>
    <form action="" method="">
        <!-- ์ฃผ์†Œ -->
        <div class="join_group">
            <label class="" for="">์ฃผ์†Œ*</label> 
            <input type="text" id="address_kakao" name="address" value="" placeholder="์ฃผ์†Œ ๊ฒ€์ƒ‰" readonly />
            <input type="text" id="detail_address" class="detail_address" name="address_detail" value="" placeholder="์ƒ์„ธ์ฃผ์†Œ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”">
        </div>
    </form>
</body>

<script>
window.onload = function(){
    document.getElementById("address_kakao").addEventListener("click", function(){ //์ฃผ์†Œ์ž…๋ ฅ์นธ์„ ํด๋ฆญํ•˜๋ฉด
        //์นด์นด์˜ค ์ง€๋„ ๋ฐœ์ƒ
        new daum.Postcode({
            oncomplete: function(data) { //์„ ํƒ์‹œ ์ž…๋ ฅ๊ฐ’ ์„ธํŒ…
                document.getElementById("address_kakao").value = data.address; // ์ฃผ์†Œ ๋„ฃ๊ธฐ
                document.querySelector("input[name=address_detail]").focus(); //์ƒ์„ธ์ž…๋ ฅ ํฌ์ปค์‹ฑ
            }
        }).open();
    });
}
</script>
</html>


๐ŸŸข HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Kakao API</title>

    <!-- css, js ์—ฐ๊ฒฐ -->
    <link rel="stylesheet" href="../common/css/style.css">
    <script src="../common/js/joinForm.js"></script>
    <script src="//t1.daumcdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js"></script>
</head>
<body>
    <form action="" method="">
        <!-- ์ฃผ์†Œ -->
        <div class="join_group">
            <label class="" for="">์ฃผ์†Œ*</label> 
            <input type="text" id="address_kakao" name="address" value="" placeholder="์ฃผ์†Œ ๊ฒ€์ƒ‰" readonly />
            <input type="text" id="detail_address" class="detail_address" name="address_detail" value="" placeholder="์ƒ์„ธ์ฃผ์†Œ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”">
        </div>
    </form>
</body>
</html>

 

๐ŸŸ  CSS

@charset "UTF-8";

.join_group {
box-sizing: border-box;
padding: 5px 0px 5px 0px;
}
.join_group > label {
    display: inline-block;
    box-sizing: border-box;
    width: 110px;
    margin: 0px 15px 0px 10px;
    font-size: 14px;
}
.join_group > input {
    box-sizing: border-box;
    width : 380px;
    height : 45px;
    padding : 5px 0px 0px 10px;
    margin: 0px 10px 0px 0px;
    border-radius: 5px;
    border: 1px solid #D9D9D9;
    font-size: 12px;
}
/* ์ฃผ์†Œ */
.join_group .btn_address {
    box-sizing: border-box;
    width : 380px;
    height : 45px;
    padding : 5px 0px 0px 10px;
    margin: 0px 10px 0px 0px;
    border-radius: 5px;
    border: 1px solid #D9D9D9;
    font-size: 13px;
    color : #a3a3a3;
    cursor: pointer;
}
.join_group > .detail_address {
    margin: 10px 0px 0px 140px;
    cursor: pointer;
}

 

๐Ÿ”ต JS

// ์ฃผ์†Œ์ฐฝ ๋„์šฐ๊ธฐ
$(document).ready(function () {
    document.getElementById("address_kakao").addEventListener("click", function(){ //์ฃผ์†Œ์ž…๋ ฅ์นธ์„ ํด๋ฆญํ•˜๋ฉด
        //์นด์นด์˜ค ์ง€๋„ ๋ฐœ์ƒ
        new daum.Postcode({
            oncomplete: function(data) { //์„ ํƒ์‹œ ์ž…๋ ฅ๊ฐ’ ์„ธํŒ…
                document.getElementById("address_kakao").value = data.address; // ์ฃผ์†Œ ๋„ฃ๊ธฐ
                document.querySelector("input[name=address_detail]").focus(); //์ƒ์„ธ์ž…๋ ฅ ํฌ์ปค์‹ฑ
            }
        }).open();
    });

});
728x90
๋ฐ˜์‘ํ˜•