Skip to content
Snippets Groups Projects
Search.js 1.81 KiB
Newer Older
LEE's avatar
LEE committed
import React, {useState} from "react";
LEE's avatar
LEE committed
import { Map, MapMarker } from "react-kakao-maps-sdk";

const {kakao} = window;

//카카오 지도 API를 이용한 검색(예정)
LEE's avatar
LEE committed

function SearchMap(props){
    // 아주대학교를 기본 위치로 설정
    const [state, setState] = useState({
        center: { lat: 37.28238488648025, lng: 127.04350967609274 },
        isPanto: true,
    });
LEE's avatar
LEE committed
    const [searchAddress, SetSearchAddress] = useState(); //주소 입력
LEE's avatar
LEE committed

    const handleInput = (e) => {
LEE's avatar
LEE committed
        SetSearchAddress(e.target.value);
    }

LEE's avatar
LEE committed
    const SearchStart = () => {
LEE's avatar
LEE committed
        console.log('Start Search!');// action test
        // 주소를 기반으로 한 검색 구현(제주특별자치도 제주시 첨단로 242 를 입력하면 kakao가 나온다)
        const geocoder = new kakao.maps.services.Geocoder();
        let callback = function(result, status) {
            if (status === kakao.maps.services.Status.OK) {
            const newSearch = result[0]
            setState({
                center: { lat: newSearch.y, lng: newSearch.x }
            })
            }
        };
        geocoder.addressSearch(`${searchAddress}`, callback);
LEE's avatar
LEE committed
    }

    return (
        <div className="UserInput">
LEE's avatar
LEE committed
            <input  onChange={handleInput}/>
LEE's avatar
LEE committed
            <button onClick={SearchStart}>검색!</button>
LEE's avatar
LEE committed
            <Map // 지도를 표시할 Container
                center={state.center}
                isPanto={state.isPanto}
                style={{
                    // 지도의 크기
                    width: "100%",
                    height: "450px",
                    }}
                level={3}>
            </Map>
LEE's avatar
LEE committed
        </div>
    )
}
LEE's avatar
LEE committed

function Search(props) {
    return (
		<div className="search">
			<h1>검색페이지입니다.</h1>
LEE's avatar
LEE committed
            <SearchMap/>
LEE's avatar
LEE committed
		</div>
    );
}

export default Search;