mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 11:06:40 +07:00
current user location
This commit is contained in:
parent
5e3aa587c7
commit
a574b7393d
12 changed files with 205 additions and 77 deletions
|
@ -1,3 +1,38 @@
|
|||
import { MOBILE_BREAKPOINT } from '~/config/frontend';
|
||||
import { LatLngLiteral } from 'leaflet';
|
||||
|
||||
export const isMobile = (): boolean => (window.innerWidth <= MOBILE_BREAKPOINT);
|
||||
export const isMobile = (): boolean => window.innerWidth <= MOBILE_BREAKPOINT;
|
||||
|
||||
export const getLocation = (callback: (pos: LatLngLiteral) => void) => {
|
||||
window.navigator.geolocation.getCurrentPosition(position => {
|
||||
console.log('getting pos');
|
||||
|
||||
if (!position || !position.coords || !position.coords.latitude || !position.coords.longitude)
|
||||
return callback(null);
|
||||
|
||||
const { latitude: lat, longitude: lng } = position.coords;
|
||||
|
||||
callback({ lat, lng });
|
||||
return;
|
||||
});
|
||||
};
|
||||
|
||||
export const watchLocation = (callback: (pos: LatLngLiteral) => void): number => {
|
||||
return window.navigator.geolocation.watchPosition(
|
||||
position => {
|
||||
console.log('Watch?');
|
||||
|
||||
if (!position || !position.coords || !position.coords.latitude || !position.coords.longitude)
|
||||
return callback(null);
|
||||
|
||||
const { latitude: lat, longitude: lng } = position.coords;
|
||||
|
||||
callback({ lat, lng });
|
||||
return;
|
||||
},
|
||||
() => callback(null),
|
||||
{
|
||||
timeout: 30,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue