Skip to content

Commit 813922e

Browse files
committed
feat: 현재 위치 받아오기 추가
1 parent 0caa902 commit 813922e

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

src/pages/main/Node.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import AddressCopy from '@/shared/components/button/AddressCopy';
33
import LocationCard from '@/shared/components/container/LocationCard';
44
import { Icon } from '@/shared/icons';
55
import { cn } from '@/shared/lib';
6+
import { getLocation } from '@/shared/utils/handleGetLocation';
67
import Image from 'next/image';
7-
88
import { useRouter } from 'next/router';
99

1010
const Board = () => {
1111
const router = useRouter();
1212
const { label } = router.query;
13-
const isStamp = true; // 스탬프 획득 여부 (임시)
13+
const isStamp = true;
1414

1515
return (
1616
<div className='relative w-full h-[100vh] overflow-auto px-[2.4rem]'>
@@ -34,14 +34,13 @@ const Board = () => {
3434

3535
<button
3636
className={cn('absolute bottom-0 right-0', isStamp && 'p-[2.5rem]')}
37-
onClick={() => {
38-
//TODO: 리워드 페이지로 이동
39-
// router.push({
40-
// pathname: '/main/riward',
41-
// query: { label },
42-
// });
43-
console.log('리워드 페이지로 이동');
44-
}}
37+
onClick={() =>
38+
getLocation(
39+
(pos) => console.log('📍 현재 위치:', pos.coords),
40+
(err) => console.error('⚠️ 위치 에러:', err.message),
41+
//TODO : 리워드 페이지로 이동 , 위치 에러일경우 모달창
42+
)
43+
}
4544
>
4645
<Icon
4746
name={isStamp ? 'Stamp' : 'PressStamp'}
@@ -58,6 +57,7 @@ const Board = () => {
5857
variant='mint'
5958
size='large'
6059
/>
60+
6161
<AddressCopy
6262
variant='mint'
6363
value='인천광역시 계양구 오조산로 31길(복사되어야할 주소)'

src/pages/main/components/board/Boardgame.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const Boardgame = () => {
3636
<div
3737
key={key}
3838
onClick={() => {
39+
// TODO : 로그인 여부 체크
3940
router.push({
4041
pathname: '/main/Node',
4142
query: { label: cell.label },
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// src/shared/utils/getLocation.ts
2+
export const getLocation = (
3+
onSuccess: (pos: GeolocationPosition) => void,
4+
onError?: (err: GeolocationPositionError) => void,
5+
) => {
6+
if (!navigator.geolocation) {
7+
console.error('❌ 현재 브라우저에서 위치 정보 사용이 불가능합니다.');
8+
return;
9+
}
10+
11+
navigator.geolocation.getCurrentPosition(onSuccess, onError, {
12+
enableHighAccuracy: true,
13+
timeout: 5000,
14+
maximumAge: 0,
15+
});
16+
};

0 commit comments

Comments
 (0)