forked from kalmtalyst/Sesac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisitMap.js
48 lines (36 loc) ยท 1.31 KB
/
VisitMap.js
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import React, { useEffect } from 'react';
import './visit.css';
const { kakao } = window;
export default function VisitMap(){
useEffect(()=> {
const container = document.getElementById('map');
const options = {
center: new kakao.maps.LatLng(33.450701, 126.570667),// ์ง๋์ ์ค์ฌ์ขํ
level: 3 // ์ง๋ ํ๋๋ ๋ฒจ
}
const map = new window.kakao.maps.Map(container, options);
const geocoder = new kakao.maps.services.Geocoder();
// ์ฃผ์๋ก ์ขํ๋ฅผ ๊ฒ์ํฉ๋๋ค
geocoder.addressSearch('์์ธํน๋ณ์ ์ค๋๋ก 121', function(result, status) {
// ์ ์์ ์ผ๋ก ๊ฒ์์ด ์๋ฃ๋์ผ๋ฉด
if (status === kakao.maps.services.Status.OK) {
const coords = new kakao.maps.LatLng(result[0].y, result[0].x);
// ๊ฒฐ๊ณผ๊ฐ์ผ๋ก ๋ฐ์ ์์น๋ฅผ ๋ง์ปค๋ก ํ์ํฉ๋๋ค
const marker = new kakao.maps.Marker({
map: map,
position: coords
});
const infowindow = new kakao.maps.InfoWindow({
content: '<div style="width:150px;text-align:center;padding:6px 0;">์กํ๋ฌ๋์ผํฐ</div>'
});
infowindow.open(map, marker);
// ์ง๋์ ์ค์ฌ์ ๊ฒฐ๊ณผ๊ฐ์ผ๋ก ๋ฐ์ ์์น๋ก ์ด๋์ํต๋๋ค
map.setCenter(coords);
}
});
}, []);
return(
<div id="map">
</div>
)
}