Skip to content

Commit edbc3b5

Browse files
committed
code adjustments
1 parent 4005e61 commit edbc3b5

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

apps/app/src/constants/geolocation.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ export const TARGET_LAT: number = 43.508133;
22

33
export const TARGET_LON: number = 16.440193;
44

5-
export const VALIDATION_RADIUS_M: number = 250;
5+
export const VALIDATION_RADIUS_M: number = 350;
66

7-
export const ACCURACY_LIMIT_M: number = 250;
8-
9-
export const EARTH_RADIUS_M: number = 6371000; // Earth radius (m)
7+
export const EARTH_RADIUS_M: number = 6371000;

apps/app/src/hooks/useGeoValidation.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { useCallback, useEffect, useMemo, useState } from 'react';
22
import { validateWithinRadius } from '@/validation/validateGeolocation';
3-
import { ACCURACY_LIMIT_M } from '@/constants/geolocation';
3+
import { VALIDATION_RADIUS_M } from '@/constants/geolocation';
44

55
type GeoResult = {
6-
ok: boolean;
6+
isOk: boolean;
77
distanceMeters: number;
88
accuracyMeters: number | null;
99
};
@@ -12,12 +12,11 @@ export function useGeoValidation(options?: {
1212
accuracyLimitMeters?: number;
1313
geolocationOptions?: PositionOptions;
1414
}) {
15-
const accuracyLimit = options?.accuracyLimitMeters ?? ACCURACY_LIMIT_M;
15+
const accuracyLimit = options?.accuracyLimitMeters ?? VALIDATION_RADIUS_M;
1616
const geoOptions = useMemo(
1717
() =>
1818
options?.geolocationOptions ?? {
19-
// koristit ce vise baterije radi gps-a, mozda nam se neisplati
20-
// enableHighAccuracy: true,
19+
enableHighAccuracy: true,
2120
timeout: 15000,
2221
maximumAge: 0,
2322
},
@@ -42,28 +41,29 @@ export function useGeoValidation(options?: {
4241
const accuracy = pos.coords.accuracy ?? null;
4342

4443
// Reject low-accuracy fixes first
45-
if (accuracy == null || accuracy > accuracyLimit) {
44+
if (!accuracy || accuracy > accuracyLimit) {
4645
const msg = `Location accuracy too low (${accuracy ? Math.round(accuracy) : '?'}m).`;
4746
setIsOk(false);
4847
setError(msg);
4948
setResult(
50-
accuracy == null
49+
!accuracy
5150
? null
52-
: { ok: false, distanceMeters: NaN, accuracyMeters: accuracy },
51+
: { isOk: false, distanceMeters: NaN, accuracyMeters: accuracy },
5352
);
5453
return;
5554
}
5655

57-
const r = validateWithinRadius(pos.coords);
56+
const { isOk, distanceMeters } = validateWithinRadius(pos.coords);
5857

5958
const payload: GeoResult = {
60-
ok: r.ok,
61-
distanceMeters: r.distanceMeters,
59+
isOk,
60+
distanceMeters,
6261
accuracyMeters: accuracy,
6362
};
6463

6564
setResult(payload);
66-
setIsOk(r.ok);
65+
setIsOk(isOk);
66+
console.log('Geo validation result:', payload);
6767
},
6868
(err) => {
6969
setIsOk(false);

apps/app/src/validation/validateGeolocation.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import {
55
VALIDATION_RADIUS_M,
66
} from '@/constants/geolocation';
77

8-
/* const TARGET = { lat: 43.393407, lon: 16.281887 }; */ // example (Split)
8+
99
type Coordinates = {
1010
lat: number;
1111
lon: number;
1212
};
1313

14-
const TARGET_COORDS: Coordinates = { lat: TARGET_LAT, lon: TARGET_LON }; // DUMP location
14+
/* const TARGET_COORDS = { lat: 43.393407, lon: 16.281887 }; */ // for testing, set to your location
15+
const TARGET_COORDS: Coordinates = { lat: TARGET_LAT, lon: TARGET_LON };
1516

1617
// Haversine distance in meters
1718
export function distanceMeters(a: Coordinates, b: Coordinates): number {
@@ -40,7 +41,7 @@ export function validateWithinRadius(userCoords: GeolocationCoordinates) {
4041
const dist = distanceMeters(user, TARGET_COORDS);
4142

4243
return {
43-
ok: dist <= VALIDATION_RADIUS_M,
44+
isOk: dist <= VALIDATION_RADIUS_M,
4445
distanceMeters: dist,
4546
accuracyMeters: userCoords.accuracy, // reported by device
4647
};

0 commit comments

Comments
 (0)