Newer
Older
import React, { useState, useEffect, useContext } from 'react';
import {Routes, Route, Link, useNavigate, Navigate } from 'react-router-dom';
import SearchMap from '../components/SearchMapByKeyword.js'
import { UserContext } from '../Context.js';
function SearchMap(props){
// 아주대학교를 기본 위치로 설정
const [state, setState] = useState({
center: { lat: 37.28238488648025, lng: 127.04350967609274 },
isPanto: true,
});
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);
const userContext = useContext(UserContext);
const navigate = useNavigate();
function MoveTo(link){
navigate(link)
}
const [location, setLocation] = useState({
keyword: "",
center: { lat: null, lng: null }
});
useEffect(() => {
const session = userContext.CheckSession()
.then((response) => {
if (!response.data) {
alert("세션이 만료되었습니다. 다시 로그인 바랍니다.")
MoveTo('/login')
}
})
.catch((response)=>{
console.log("error!:LogOut")
console.log(response)
})
});
<SearchMap loc={location} setLoc={setLocation}></SearchMap>