TP-44059 | Geolocation Fix
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
<uses-feature android:name="android.hardware.camera" android:required="false" />
|
||||
<uses-feature android:name="android.hardware.camera.front" android:required="false" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
||||
<uses-permission android:name="android.permission.READ_SMS" />
|
||||
|
||||
|
||||
@@ -114,6 +114,7 @@ const TrackingComponent: React.FC<ITrackingComponent> = ({ children }) => {
|
||||
isActiveOnApp: Boolean(isActiveOnApp),
|
||||
userActivityOnApp: String(userActivityonApp),
|
||||
};
|
||||
dispatch(setDeviceGeolocationsBuffer(geolocation));
|
||||
dispatch(sendLocationAndActivenessToServer([geolocation]));
|
||||
} catch (e: any) {
|
||||
logError(e, 'Error during background location sending.');
|
||||
|
||||
@@ -6,6 +6,12 @@ import { addClickstreamEvent } from '../../../services/clickstreamEventService';
|
||||
import { CLICKSTREAM_EVENT_NAMES } from '../../../common/Constants';
|
||||
const FIVE_MIN = 5 * 60 * 1000;
|
||||
|
||||
export interface DeviceLocation {
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
export class CaptureGeolocation {
|
||||
private static capturedLocation: {
|
||||
[caseId: string]: {
|
||||
@@ -72,7 +78,35 @@ export class CaptureGeolocation {
|
||||
text1: 'Error getting geolocation' + JSON.stringify(error || {}),
|
||||
});
|
||||
},
|
||||
{ enableHighAccuracy: true, timeout: 1e4, maximumAge: 1e4, showLocationDialog: false }
|
||||
{ enableHighAccuracy: true, timeout: 1e4, maximumAge: 1e4, forceRequestLocation: true }
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
static async watchLocation(
|
||||
callbackFn: (location: DeviceLocation) => void
|
||||
): Promise<Geolocation.GeoCoordinates | undefined> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const isLocationOn = await PermissionsAndroid.check(
|
||||
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
|
||||
);
|
||||
if (!isLocationOn) {
|
||||
resolve(undefined);
|
||||
}
|
||||
Geolocation.watchPosition(
|
||||
(position) => {
|
||||
callbackFn?.({
|
||||
latitude: position.coords.latitude,
|
||||
longitude: position.coords.longitude,
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
resolve(position.coords);
|
||||
},
|
||||
(error) => {
|
||||
logError(error as any, 'Unable to get location');
|
||||
reject(error);
|
||||
},
|
||||
{ enableHighAccuracy: true, distanceFilter: 1, forceRequestLocation: true }
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -149,7 +149,9 @@ function AddressItem({
|
||||
<Text numberOfLines={1} ellipsizeMode="tail" style={[GenericStyles.ml4]}>
|
||||
{showRelativeDistance && relativeDistanceBwLatLong ? (
|
||||
<>({relativeDistanceFormatter(relativeDistanceBwLatLong)} km away)</>
|
||||
) : null}
|
||||
) : (
|
||||
'--'
|
||||
)}
|
||||
</Text>
|
||||
</View>
|
||||
{lastFeedbackForAddress?.feedbackPresent ? (
|
||||
|
||||
@@ -126,21 +126,19 @@ const AddressGeolocation: React.FC<IAddressGeolocation> = ({ route: routeParams
|
||||
useEffect(() => {
|
||||
addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.FA_ALL_ADDRESSES_LANDED, commonParams);
|
||||
|
||||
if (!currentGeolocationCoordinates.latitude || !currentGeolocationCoordinates.longitude) {
|
||||
(async () => {
|
||||
const location = await CaptureGeolocation.fetchLocation(`${Date.now()}`, 0);
|
||||
(async () => {
|
||||
const location = await CaptureGeolocation.fetchLocation(`${Date.now()}`, 0);
|
||||
|
||||
if (location != null) {
|
||||
dispatch(
|
||||
setDeviceGeolocation({
|
||||
latitude: location.latitude,
|
||||
longitude: location.longitude,
|
||||
timestamp: Date.now(),
|
||||
})
|
||||
);
|
||||
}
|
||||
})();
|
||||
}
|
||||
if (location != null) {
|
||||
dispatch(
|
||||
setDeviceGeolocation({
|
||||
latitude: location.latitude,
|
||||
longitude: location.longitude,
|
||||
timestamp: Date.now(),
|
||||
})
|
||||
);
|
||||
}
|
||||
})();
|
||||
}, []);
|
||||
|
||||
if (!isOnline) {
|
||||
|
||||
@@ -33,6 +33,8 @@ import RegisterPayments from '../registerPayements/RegisterPayments';
|
||||
import TodoList from '../todoList/TodoList';
|
||||
import UngroupedAddressContainer from '../addressGeolocation/UngroupedAddressContainer';
|
||||
import { getAgentDetail } from '../../action/authActions';
|
||||
import { CaptureGeolocation, DeviceLocation } from '@components/form/services/geoLocation.service';
|
||||
import { setDeviceGeolocation } from '@reducers/foregroundServiceSlice';
|
||||
|
||||
const Stack = createNativeStackNavigator();
|
||||
|
||||
@@ -112,6 +114,13 @@ const ProtectedRouter = () => {
|
||||
// Firestore listener hook
|
||||
useFirestoreUpdates();
|
||||
|
||||
React.useEffect(() => {
|
||||
// Watching Position for significant change
|
||||
CaptureGeolocation.watchLocation((location: DeviceLocation) =>
|
||||
dispatch(setDeviceGeolocation(location))
|
||||
);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Stack.Navigator
|
||||
screenOptions={{ freezeOnBlur: true, animation: 'none', animationDuration: 0 }}
|
||||
|
||||
Reference in New Issue
Block a user