11# react-naver-map
22
33## Introduction
4+
45네이버 맵을 리액트에서 사용하기 편하게 만들어 둔 라이브러리입니다.
56
67## Installation
@@ -17,27 +18,71 @@ pnpm add @r2don/react-naver-map
1718```
1819
1920## Usage
21+
2022> 기본 스타일이 적용되어있지 않으니, 필요에 맞게 width와 height를 적용해주세요.
23+
2124### Map component
2225
2326``` js
24- import { Map , useNaverMapInit , Marker } from ' @r2don/react-naver-map'
27+ import { Map , useNaverMapInit , Marker } from " @r2don/react-naver-map" ;
2528
2629const MARKERS = [
27- {latitude: 37. , longitude: 127 },
28- {latitude: 37.5 , longitude: 127.5 },
29- {latitude: 38 , longitude: 128 },
30- {latitude: 38.5 , longitude: 128.5 },
31- ]
30+ { latitude: 37 , longitude: 127 },
31+ { latitude: 37.5 , longitude: 127.5 },
32+ { latitude: 38 , longitude: 128 },
33+ { latitude: 38.5 , longitude: 128.5 },
34+ ];
35+
36+ function App () {
37+ const { isLoaded } = useNaverMapInit ();
38+
39+ if (! isLoaded) return null ;
40+
41+ return (
42+ < Map
43+ center= {{ latitude: 37.3595704 , longitude: 127.105399 }}
44+ style= {{ height: " 500px" , width: " 500px" }}
45+ >
46+ {MARKERS .map ((marker ) => (
47+ < Marker key= {JSON .stringify (marker)} position= {marker} / >
48+ ))}
49+ < / Map >
50+ );
51+ }
52+ ```
53+
54+ ### PolyLine Component
55+
56+ ``` js
57+ import { Map , useNaverMapInit , Marker , Poly } from " @r2don/react-naver-map" ;
58+
59+ const MARKERS = [
60+ { latitude: 37 , longitude: 127 },
61+ { latitude: 37.5 , longitude: 127.5 },
62+ { latitude: 38 , longitude: 128 },
63+ { latitude: 38.5 , longitude: 128.5 },
64+ ];
65+
66+ function App () {
67+ const { isLoaded } = useNaverMapInit ();
3268
33- function App () {
34- const {isLoaded } = useNaverMapInit ();
69+ if (! isLoaded) return null ;
3570
36- if (! isLoaded) return null ;
71+ const path = [{ latitude: 37.3595704 ; longitude: 127.105399 }, { latitude: 37.3585781 ; longitude: 127.1053234 }];
72+ const mid = {
73+ latitude: (path[0 ].latitude + path[1 ].latitude ) / 2 ,
74+ longitude: (path[0 ].longitude + path[1 ].longitude ) / 2 ,
75+ }
3776
3877 return (
39- < Map center= {{latitude: 37.3595704 , longitude: 127.105399 }} style= {{height: ' 500px' , width: ' 500px' }}>
40- {MARKERS .map ((marker ) => < Marker key= {JSON .stringify (marker)} position= {marker} / > )}
78+ < Map
79+ center= {{ latitude: mid .latitude , longitude: mid .longitude }}
80+ style= {{ height: " 500px" , width: " 500px" }}
81+ >
82+ {MARKERS .map ((marker ) => (
83+ < Marker key= {JSON .stringify (marker)} position= {marker} / >
84+ ))}
85+ < Polyline path= {path} / >
4186 < / Map >
4287 );
4388}
@@ -47,4 +92,4 @@ function App () {
4792
4893Licensed under the MIT License, Copyright (c) 2022 r2don.
4994
50- See [ LICENSE] ( https://github.com/r2don/react-naver-map/blob/main/LICENSE ) for more information.
95+ See [ LICENSE] ( https://github.com/r2don/react-naver-map/blob/main/LICENSE ) for more information.
0 commit comments