wujingjing
2024-11-27 6713c4f475408198aa7c6be301195e3c04cdd764
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
export function getCurrentPosition() {
    const p = new Promise<GeolocationPosition | null>((resolve, reject) => {
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(
                (position) => resolve(position),
                (error) => {
                    resolve(null);
                }
            );
        } else {
            console.log('Geolocation is not supported by this browser.');
            resolve(null);
        }
    });
    return p;
}