260714_01_ENH: geolocation.ts 추가
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@kri/common",
|
"name": "@kri/common",
|
||||||
"version": "0.16.0",
|
"version": "0.11.0",
|
||||||
"description": "KRI 프런트엔드 공통 유틸리티",
|
"description": "KRI 프런트엔드 공통 유틸리티",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
|
|||||||
27
src/browser/geolocation.ts
Normal file
27
src/browser/geolocation.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
export type GeoPositionMeta = {
|
||||||
|
latitude?: number;
|
||||||
|
longitude?: number;
|
||||||
|
accuracy?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getCurrentPositionMeta = (
|
||||||
|
timeoutMs = 5000,
|
||||||
|
): Promise<GeoPositionMeta> => {
|
||||||
|
if (typeof navigator === "undefined" || !navigator.geolocation) {
|
||||||
|
return Promise.resolve({});
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
navigator.geolocation.getCurrentPosition(
|
||||||
|
(position) => {
|
||||||
|
resolve({
|
||||||
|
latitude: position.coords.latitude,
|
||||||
|
longitude: position.coords.longitude,
|
||||||
|
accuracy: position.coords.accuracy,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
() => resolve({}),
|
||||||
|
{ timeout: timeoutMs, maximumAge: 60_000 },
|
||||||
|
);
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
export * from "./file-download.js";
|
export * from "./file-download.js";
|
||||||
export * from "./cookie-store.js";
|
export * from "./cookie-store.js";
|
||||||
export * from "./json-storage.js";
|
export * from "./json-storage.js";
|
||||||
|
export * from "./geolocation.js";
|
||||||
|
|||||||
Reference in New Issue
Block a user