HTML


게시글 '다음 도로명주소 검색API 연계 예제'에 대한 정보
다음 도로명주소 검색API 연계 예제
등록일 2016-12-22 조회 1,575

기본 도로명주소 입력이고 없을경우 지번주소로 대체

<div>
 <input type="text" name="us_zip_01" id="us_zip_01" size="5" maxlength="5" value="" title="우편번호" />
 <button class="greenWbtn" onclick="execDaumPostcode();return false;">주소검색</button>
</div>
<div style="padding-top:5px;"><input type="text" name="us_address" id="us_address" size="40" maxlength="40" value="" title="주소" />
<input type="text" name="us_address_etc" id="us_address_etc" size="20" maxlength="20" value="" title="나머지 주소" /></div>
<script src="http://dmaps.daum.net/map_js_init/postcode.v2.js"></script>
<script type="text/javascript">
function execDaumPostcode() {
 new daum.Postcode({
  oncomplete: function(data) {
   var fullRoadAddr = data.roadAddress;
   var extraRoadAddr = '';
   if(data.bname !== '' && /[동|로|가]$/g.test(data.bname)){
    extraRoadAddr += data.bname;
   }
   if(data.buildingName !== '' && data.apartment === 'Y'){
    extraRoadAddr += (extraRoadAddr !== '' ? ', ' + data.buildingName : data.buildingName);
   }
   if(extraRoadAddr !== ''){
    extraRoadAddr = ' (' + extraRoadAddr + ')';
   }
   if(fullRoadAddr !== ''){
    fullRoadAddr += extraRoadAddr;
   }
   document.getElementById('us_zip_01').value = data.zonecode;
   document.getElementById('us_address').value = (fullRoadAddr=="") ? data.address : fullRoadAddr;
   document.getElementById('us_address_etc').value = "";
  }
 }).open();
}
</script>


링크#1 http://postcode.map.daum.net/guide