Skip to content

Commit 6ac22b2

Browse files
committed
๐Ÿ“ docs: useGeolocation ๋ฌธ์„œ ์ž‘์„ฑ
1 parent c4df0a4 commit 6ac22b2

File tree

2 files changed

+97
-1
lines changed

2 files changed

+97
-1
lines changed

โ€Ždocs/pages/docs/hooks/_meta.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"useTranslation": "useTranslation",
3-
"useMousePosition": "useMousePosition"
3+
"useMousePosition": "useMousePosition",
4+
"useGeolocation" : "useGeolocation"
45
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { Callout } from 'nextra/components';
2+
3+
# useGeolocation
4+
5+
<Callout type="info">
6+
์ด ํ›…์€ ๋ธŒ๋ผ์šฐ์ €์˜ Geolocation API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‚ฌ์šฉ์ž์˜ ์œ„์น˜ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.
7+
์ง€์›๋˜์ง€ ์•Š๋Š” ๋ธŒ๋ผ์šฐ์ €์—์„œ๋Š” ์ •ํ™•ํ•œ ์œ„์น˜ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
8+
</Callout>
9+
10+
## Introduce
11+
12+
`useGeolocation` ํ›…์€ ์‚ฌ์šฉ์ž์˜ ์œ„์น˜ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์™€ ์ƒํƒœ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
13+
์ด ํ›…์€ ์œ„์น˜ ์ •๋ณด์˜ ์œ„๋„, ๊ฒฝ๋„, ๊ณ ๋„ ๋“ฑ ๋‹ค์–‘ํ•œ ์œ„์น˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋ฉฐ, ์œ„์น˜ ์ •๋ณด ์ˆ˜์ง‘ ์ค‘ ๋ฐœ์ƒํ•œ ์˜ค๋ฅ˜๋„ ํ•จ๊ป˜ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
14+
15+
```ts
16+
export interface UseGeolocationReturnType {
17+
loading: boolean;
18+
error: GeolocationPositionError | null;
19+
timestamp?: EpochTimeStamp;
20+
latitude?: number;
21+
longitude?: number;
22+
altitude?: number;
23+
accuracy?: number;
24+
altitudeAccuracy?: number;
25+
heading?: number;
26+
speed?: number;
27+
}
28+
29+
const useGeolocation = (
30+
options?: PositionOptions
31+
): UseGeolocationReturnType;
32+
```
33+
34+
### Props
35+
36+
- `options` : ์œ„์น˜ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜ฌ ๋•Œ ์‚ฌ์šฉํ•  ์˜ต์…˜
37+
- `enableHighAccuracy` : ์œ„์น˜ ์ •๋ณด๋ฅผ ๋†’์€ ์ •ํ™•๋„๋กœ ์ˆ˜์ง‘ํ• ์ง€ ์—ฌ๋ถ€ (๊ธฐ๋ณธ๊ฐ’: `false`)
38+
- `timeout` : ์œ„์น˜ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜ค๊ธฐ ์œ„ํ•ด ๋Œ€๊ธฐํ•  ์ตœ๋Œ€ ์‹œ๊ฐ„ (๋ฐ€๋ฆฌ์ดˆ ๋‹จ์œ„)
39+
- `maximumAge` : ์œ„์น˜ ์ •๋ณด๋ฅผ ์บ์‹ฑํ•  ์ตœ๋Œ€ ์‹œ๊ฐ„ (๋ฐ€๋ฆฌ์ดˆ ๋‹จ์œ„)
40+
41+
### Returns
42+
43+
- `loading: boolean` : ์œ„์น˜ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ์ค‘์ธ์ง€ ์—ฌ๋ถ€
44+
- `error: GeolocationPositionError | null` : ๋ฐœ์ƒํ•œ ์˜ค๋ฅ˜
45+
- `timestamp?: EpochTimeStamp` : ์œ„์น˜ ์ •๋ณด์˜ ํƒ€์ž„์Šคํƒฌํ”„
46+
- `latitude?: number` : ํ˜„์žฌ ์œ„์น˜์˜ ์œ„๋„
47+
- `longitude?: number` : ํ˜„์žฌ ์œ„์น˜์˜ ๊ฒฝ๋„
48+
- `altitude?: number` : ํ˜„์žฌ ์œ„์น˜์˜ ๊ณ ๋„
49+
- `accuracy?: number` : ์œ„์น˜ ์ •๋ณด์˜ ์ •ํ™•๋„
50+
- `altitudeAccuracy?: number` : ๊ณ ๋„ ์ •๋ณด์˜ ์ •ํ™•๋„
51+
- `heading?: number` : ์ด๋™ ๋ฐฉํ–ฅ
52+
- `speed?: number` : ํ˜„์žฌ ์†๋„
53+
54+
## Examples
55+
56+
```ts copy filename="GeolocationComponent.tsx"
57+
import useGeolocation from './useGeolocation';
58+
59+
const GeolocationComponent = () => {
60+
const {
61+
latitude,
62+
longitude,
63+
altitude,
64+
accuracy,
65+
altitudeAccuracy,
66+
heading,
67+
speed,
68+
timestamp,
69+
error,
70+
loading,
71+
} = useGeolocation({ enableHighAccuracy: true });
72+
73+
if (loading) {
74+
return <p>์œ„์น˜ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ์ค‘์ž…๋‹ˆ๋‹ค...</p>;
75+
}
76+
77+
if (error) {
78+
return <p>์˜ค๋ฅ˜ ๋ฐœ์ƒ: {error.message}</p>;
79+
}
80+
81+
return (
82+
<div>
83+
<h2>์œ„์น˜ ์ •๋ณด</h2>
84+
<p>์œ„๋„: {latitude}</p>
85+
<p>๊ฒฝ๋„: {longitude}</p>
86+
<p>๊ณ ๋„: {altitude}</p>
87+
<p>์ •ํ™•๋„: {accuracy} meters</p>
88+
<p>๊ณ ๋„ ์ •ํ™•๋„: {altitudeAccuracy} meters</p>
89+
<p>๋ฐฉํ–ฅ: {heading} degrees</p>
90+
<p>์†๋„: {speed} m/s</p>
91+
<p>ํƒ€์ž„์Šคํƒฌํ”„: {new Date(timestamp || 0).toLocaleTimeString()}</p>
92+
</div>
93+
);
94+
};
95+
```

0 commit comments

Comments
ย (0)