Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>관광정보</title>
- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
- <link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/start/jquery-ui.css">
- <script src="http://code.jquery.com/jquery-1.12.1.min.js"></script>
- <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
- </head>
- <body>
- <div class="container">
- <div class="jumbotron text-center">
- <h1>한국관광지정보</h1>
- </div>
- <div class="main">
- <form onsubmit="return false;" class="form-inline">
- <select name="areaCode" id="areaCode" class="form-control">
- <option value="">지역코드</option>
- </select>
- </form>
- </div>
- <div class="list">
- <table class="table">
- <thead class="thead-dark">
- <tr>
- <th>사진</th>
- <th>관광지명</th>
- <th>주소</th>
- <th>연락처</th>
- <th>경도</th>
- <th>위도</th>
- </tr>
- </thead>
- <tbody>
- </tbody>
- </table>
- </div>
- </div>
- <div id="pop" style="display: none;">
- <h2 id="detail-title" class="detail-info"></h2>
- <p>주소: <span id="detail-addr" class="detail-info"></span></p>
- <p>전화: <span id="detail-tel" class="detail-info"></span></p>
- <p>좌표: <span id="detail-mapxy" class="detail-info"></span></p>
- <p>설명: <span id="detail-overview" class="detail-info"></span></p>
- <p><img id="detail-pic" src="" class="detail-img" style="max-width: 90%;"></p>
- </div>
- <script>
- var ServiceKey = "서비스인증키";
- var params = '?' + encodeURIComponent('ServiceKey') + '='+ServiceKey; /*Service Key*/
- params += '&' + encodeURIComponent('ServiceKey') + '=' + encodeURIComponent(ServiceKey);
- params += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('10'); /*한 페이지 결과 수*/
- params += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /*현재 페이지 번호*/
- params += '&' + encodeURIComponent('MobileOS') + '=' + encodeURIComponent('ETC'); /*IOS(아이폰),AND(안드로이드),WIN(원도우폰),ETC*/
- params += '&' + encodeURIComponent('MobileApp') + '=' + encodeURIComponent('AppTest'); /*서비스명=어플명*/
- params += '&' + encodeURIComponent('defaultYN') + '=' + encodeURIComponent('Y'); /*기본정보 조회여부*/
- params += '&' + encodeURIComponent('firstImageYN') + '=' + encodeURIComponent('Y'); /*원본, 썸네일 대표이미지 조회여부*/
- params += '&' + encodeURIComponent('areacodeYN') + '=' + encodeURIComponent('Y'); /*지역코드, 시군구코드 조회여부*/
- params += '&' + encodeURIComponent('catcodeYN') + '=' + encodeURIComponent('Y'); /*대,중,소분류코드 조회여부*/
- params += '&' + encodeURIComponent('addrinfoYN') + '=' + encodeURIComponent('Y'); /*주소, 상세주소 조회여부*/
- params += '&' + encodeURIComponent('mapinfoYN') + '=' + encodeURIComponent('Y'); /*좌표 X,Y 조회여부*/
- params += '&' + encodeURIComponent('overviewYN') + '=' + encodeURIComponent('Y'); /*콘텐츠 개요 조회여부*/
- //params += '&' + encodeURIComponent('contentId') + '=' + encodeURIComponent(''); /*콘텐츠ID*/
- //params += '&' + encodeURIComponent('contentTypeId') + '=' + encodeURIComponent(''); /*관광타입(관광지, 숙박 등) ID*/
- function getArearCode(code) {
- var code = code ? code : "";
- var url = 'http://api.visitkorea.or.kr/openapi/service/rest/KorService/areaCode';
- url += params
- url += '&' + encodeURIComponent('areaCode') + '=' + encodeURIComponent(code);
- console.log();
- $.get(url, function(res){
- var items = $(res).find( "item" );
- for( var i=0; i<items.length; i++ ) {
- var codeItem = $(items[i]).find( "code" );
- var code = codeItem.text();
- var nameItem = $(items[i]).find( "name" );
- var name = nameItem.text();
- var opt = "<option value='" + code + "'>" + name + "</option>";
- $("#areaCode").append(opt);
- }
- });
- }
- getArearCode();
- $("#areaCode").on("change",function(){
- var areaCode = $(this).val();
- getInfoList(areaCode);
- });
- function getInfoList(areaCode,sigunguCode){
- var areaCode = areaCode ? areaCode : "";
- var sigunguCode = sigunguCode ? sigunguCode : "1";
- var url = "http://api.visitkorea.or.kr/openapi/service/rest/KorService/areaBasedList";
- url += params;
- url += '&' + encodeURIComponent('areaCode') + '=' + encodeURIComponent(areaCode); //지역코드
- url += '&' + encodeURIComponent('sigunguCode') + '=' + encodeURIComponent(sigunguCode); //시군구 코드
- url += '&' + encodeURIComponent('listYN') + '=' + encodeURIComponent('Y'); //목록 구분
- url += '&' + encodeURIComponent('arrange') + '=' + encodeURIComponent('A'); //정력(A=제목순,B=조회순,C=수정일순,D=생성일순)
- $(".list table tbody").html("");
- $.get(url, function(res){
- var items = $(res).find( "item" );
- for( var i=0; i<items.length; i++ ) {
- console.log(items[i]);
- var title = $(items[i]).find( "title" ).text();
- var addr = $(items[i]).find( "addr1" ).text() + " " + $(items[i]).find( "addr2" ).text();
- var tel = $(items[i]).find( "tel" ).text();
- var mapx = $(items[i]).find( "mapx" ).text();
- var mapy = $(items[i]).find( "mapy" ).text();
- var firstimage = $(items[i]).find( "firstimage" ).text();
- var contentid = $(items[i]).find( "contentid" ).text();
- var tr = "<tr onclick='viewDetail(\"" + contentid + "\");'>";
- tr += "<td><img src='" + firstimage + "' width='100' height='100'></td>";
- tr += "<td>" + title + "</td>";
- tr += "<td>" + addr + "</td>";
- tr += "<td>" + tel + "</td>";
- tr += "<td>" + mapx + "</td>";
- tr += "<td>" + mapy + "</td>";
- tr += "</tr>";
- $(".list table tbody").append(tr);
- }
- });
- }
- function viewDetail(contentid) {
- var contentid = contentid ? contentid : "";
- if( ! contentid ) return;
- var url = "http://api.visitkorea.or.kr/openapi/service/rest/KorService/detailCommon";
- url += params;
- url += '&' + encodeURIComponent('contentId') + '=' + encodeURIComponent(contentid); //콘텐츠아이디
- $.get(url, function(res){
- $(".detail-info").html("");
- $(".detail-img").attr("src","");
- var items = $(res).find( "item" );
- var data = items[0];
- console.log(data);
- var title = $(data).find( "title" ).text();
- var addr = $(data).find( "zipcode" ).text() + ") " + $(data).find( "addr1" ).text() + " " + $(data).find( "addr2" ).text();
- var tel = $(data).find( "tel" ).text();
- var mapx = $(data).find( "mapx" ).text();
- var mapy = $(data).find( "mapy" ).text();
- var overview = $(data).find( "overview" ).text();
- var firstimage = $(data).find( "firstimage" ).text();
- $("#detail-title").html(title);
- $("#detail-addr").html(addr);
- $("#detail-tel").html(tel);
- $("#detail-mapxy").html(mapx + " x " + mapy);
- $("#overview").html(overview);
- $("#detail-pic").attr("src", firstimage);
- $("#pop").dialog({
- width: 600,
- height: 700,
- modal: true,
- title: title
- });
- });
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment