티스토리 뷰

 

  • 시도구군동 지번을 이용하여 위도 경도를 구하는 스크립트
<!DOCTYPE html>

<html lang="en">
  <head>
    <meta charset="UTF-8" />

    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <title>Document</title>

    <script src="https://code.jquery.com/jquery-latest.min.js"></script>

    <script
      type="text/javascript"
      src="https://openapi.map.naver.com/openapi/v3/maps.js?ncpClientId=API키넣는곳&submodules=geocoder"
    ></script>
  </head>

  <body>
    <button id="ck">DB파일읽어오기</button>
    <button id="ckk">파싱(좌표)</button>
    <button id="save">파일저장</button>

    <script>
      //

      var str = [];
      var strr = [];

      $('#ck').on('click', function () {
        $.ajax({
          type: 'GET',
          url: 'http://localhost:8000/happyhouse/map/test',
          async: false,
          dataType: 'json',

          success: function (res) {
            console.log(res);

            $.each(res, function (index, itemss) {
              str.push(itemss);
            });
          },
        });
        // console.log(str);
      });

      $('#ckk').on('click', function () {
        (function looper(i) {
          setTimeout(function () {
            runAction(i);
            if (7777 > ++i) looper(i);
          }, 200);
        })(0);
      });

      var strrr =
        'insert into houseinfo(dong,AptName,code,buildYear,jibun,lat,lng,isApt) values ';

      var runAction = function (itv) {
        naver.maps.Service.geocode(
          {
            query: `${str[itv].dongdong}`,
          },
          function (status, response) {
            console.log(response);
            var result = response.v2, // 검색 결과의 컨테이너
              items = result.addresses; // 검색 결과의 배열
            let x = parseFloat(items[0].x); // 경도
            let y = parseFloat(items[0].y); // 위도
            // strr.push(`이름 : ${str[itv].aptName}, 위도:${y} , 경도 : ${x},`);
            strrr += `('${str[itv].dong}','${str[itv].aptName}','${str[itv].code}','${str[itv].buildYear}','${str[itv].jibun}','${y}','${x}','2'),`;
          }
        );
      };

      $('#save').on('click', function () {
        // console.log(strrr.length);
        saveToFile_Chrome('SQLTEST파일', strrr.slice(0, -1));
      });

      function saveToFile_Chrome(fileName, content) {
        var blob = new Blob([content], { type: 'text/plain' });

        objURL = window.URL.createObjectURL(blob);

        // 이전에 생성된 메모리 해제

        if (window.__Xr_objURL_forCreatingFile__) {
          window.URL.revokeObjectURL(window.__Xr_objURL_forCreatingFile__);
        }

        window.__Xr_objURL_forCreatingFile__ = objURL;

        var a = document.createElement('a');

        a.download = fileName;

        a.href = objURL;

        a.click();
      }
    </script>
  </body>
</html>

'기타' 카테고리의 다른 글

window cmd로 ssh 접속하기 (pem key)  (0) 2021.03.29
Heroku _ Spring Boot Deploy  (0) 2020.12.26
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG more
«   2025/02   »
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
글 보관함