Skip to content

๐Ÿ—บ๏ธ ์นด์นด์˜ค์ง€๋„๋ฅผ React๋กœ ๋งŒ๋“  ์˜ˆ์ œ ํŒŒ์ผ์ž…๋‹ˆ๋‹ค.

Notifications You must be signed in to change notification settings

light9639/React-KaKao-Map

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

11 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ—บ๏ธ React-Map ํ…œํ”Œ๋ฆฟ

:octocat: ๋ฐ”๋กœ๊ฐ€๊ธฐ https://light9639.github.io/React-KaKao-Map/

โœจ React-Weather ํ…œํ”Œ๋ฆฟ โœจ

๐ŸŽ‰ ์นด์นด์˜ค ๊ฐœ๋ฐœ์ž ์‚ฌ์ดํŠธ์—์„œ ๊ณ„์ • ์ •๋ณด ์ƒ์„ฑํ•˜๊ธฐ

๋‹ค์šด๋กœ๋“œ (1)

๐Ÿ“Œ ์šฐ์„  ์นด์นด์˜ค ๊ฐœ๋ฐœ์ž ์‚ฌ์ดํŠธ์— ์ ‘์†ํ•˜์—ฌ ๊ณ„์ •์„ ๋งŒ๋“ค๊ณ  ๋กœ๊ทธ์ธ ํ•ฉ๋‹ˆ๋‹ค.

1๏ธโƒฃ ๋ฉ”์ธ ํ™”๋ฉด์˜ ์ƒ๋‹จ ๋ฉ”๋‰ด ์ค‘ "๋‚ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜"์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

2๏ธโƒฃ ๋‚ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ "์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ถ”๊ฐ€ํ•˜๊ธฐ"๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

3๏ธโƒฃ ์•ฑ ์•„์ด์ฝ˜, ์•ฑ ์ด๋ฆ„, ์‚ฌ์—…์ž๋ช…์„ ์ž…๋ ฅํ•˜๊ณ  ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

4๏ธโƒฃ ์ €์žฅ์ด ์™„๋ฃŒ๋˜๋ฉด ์š”์•ฝ ์ •๋ณด ํŽ˜์ด์ง€์— ์ƒ์„ฑ๋œ "์•ฑ ํ‚ค"๊ฐ€ ๋ณด์ž…๋‹ˆ๋‹ค.

5๏ธโƒฃ ํ”Œ๋žซํผ ๋ฉ”๋‰ด์˜ "Webํ”Œ๋žซํผ ๋“ฑ๋ก"์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

6๏ธโƒฃ ์‚ฌ์ดํŠธ ๋„๋ฉ”์ธ์„ ์ž…๋ ฅํ•œ ํ›„ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

7๏ธโƒฃ Web ์‚ฌ์ดํŠธ ๋„๋ฉ”์ธ์ด ๋“ฑ๋ก๋œ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ํŽ˜์ด์ง€์—์„œ ์‚ญ์ œ๋‚˜ ์ˆ˜์ •์„ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๐ŸŽŠ ๋ฆฌ์•กํŠธ ํ”„๋กœ์ ํŠธ ์ˆ˜์ •์‚ฌํ•ญ๋“ค

  • ์šฐ์„  ๋ฆฌ์•กํŠธ ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

    npx create-react-app kakaomap
  • index.html์˜ head์— ๋‹ค์Œ ๋‚ด์šฉ์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

    <meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline' https://dapi.kakao.com http://*.daumcdn.net; script-src 'self' 'unsafe-inline' https://dapi.kakao.com http://*.daumcdn.net; img-src 'self' 'unsafe-inline' https://dapi.kakao.com http://*.daumcdn.net;">
    <meta http-equiv="X-Content-Security-Policy" content="default-src 'self' 'unsafe-inline' https://dapi.kakao.com http://*.daumcdn.net; script-src 'self' 'unsafe-inline' https://dapi.kakao.com http://*.daumcdn.net; img-src 'self' 'unsafe-inline' https://dapi.kakao.com http://*.daumcdn.net;">
    
    <script type="text/javascript" src="https://dapi.kakao.com/v2/maps/sdk.js?autoload=false&appkey=๋ฐœ๊ธ‰๋ฐ›์€ํ‚ค"></script>
  • App.js๋ฅผ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

    import './App.css';
    import { useEffect } from 'react';
    
    function App() {
    
      //์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ ์ฝ์–ด์˜ค๊ธฐ
      const new_script = src => {
        return new Promise((resolve, reject) => {
          const script = document.createElement('script');
          script.src = src;
          script.addEventListener('load', () => {
            resolve();
          });
          script.addEventListener('error', e => {
            reject(e);
          });
          document.head.appendChild(script);
        });
      };
    
      useEffect(() => {
        //์นด์นด์˜ค๋งต ์Šคํฌ๋ฆฝํŠธ ์ฝ์–ด์˜ค๊ธฐ
        const my_script = new_script('https://dapi.kakao.com/v2/maps/sdk.js?autoload=false&appkey=๋ฐœ๊ธ‰๋ฐ›์€ํ‚ค');
    
        //์Šคํฌ๋ฆฝํŠธ ์ฝ๊ธฐ ์™„๋ฃŒ ํ›„ ์นด์นด์˜ค๋งต ์„ค์ •
        my_script.then(() => {
          console.log('script loaded!!!');
          const kakao = window['kakao'];
          kakao.maps.load(() => {
            const mapContainer = document.getElementById('map');
            const options = {
              center: new kakao.maps.LatLng(37.56000302825312, 126.97540593203321), //์ขŒํ‘œ์„ค์ •
              level: 3
            };
            const map = new kakao.maps.Map(mapContainer, options); //๋งต์ƒ์„ฑ
            //๋งˆ์ปค์„ค์ •
            const markerPosition = new kakao.maps.LatLng(37.56000302825312, 126.97540593203321);
            const marker = new kakao.maps.Marker({
              position: markerPosition
            });
            marker.setMap(map);
          });
        });
      }, []);
    
      return (
        <div className="App">
          <div id="map" className="map"/>
        </div>
      );
    }
    
    export default App;
  • App.css์— class๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

    .map {
      width: 100%;
      height: 600px;
      align-items: center;
      justify-content: center;
      margin-left: auto;
      margin-right: auto;
      border-style: solid;
      border-width: medium;
      border-color: #D8D8D8;
    }

๐Ÿ—บ๏ธ ์™„์„ฑํ™”๋ฉด

๋‹ค์šด๋กœ๋“œ

  • ์ง€๋„์˜ ์ขŒํ‘œ๋Š” URL์—์„œ ์ฐพ์œผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

๐Ÿ“Ž ์ถœ์ฒ˜

About

๐Ÿ—บ๏ธ ์นด์นด์˜ค์ง€๋„๋ฅผ React๋กœ ๋งŒ๋“  ์˜ˆ์ œ ํŒŒ์ผ์ž…๋‹ˆ๋‹ค.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published