260714_01_ENH: geolocation.ts 추가
This commit is contained in:
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 },
|
||||
);
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user