Skip to content

Got incorrect speed. #5

@black1ava

Description

@black1ava

I am using @hariks789/react-native-background-geolocation and try to get speed when my phone is moving. But event though my phone I still got speed 1km/h, 2km/h... . The worst case is 26km/h.

Your Environment

"dependencies": {
"@hariks789/react-native-background-geolocation": "^0.7.1",
"@notifee/react-native": "^7.4.0",
"@react-native-async-storage/async-storage": "^1.17.11",
"@react-native-community/masked-view": "^0.1.11",
"@react-native-community/netinfo": "^9.3.7",
"@react-native-firebase/app": "^16.5.0",
"@react-native-firebase/firestore": "^16.5.0",
"@react-native-firebase/functions": "^16.5.0",
"@react-native-firebase/messaging": "^16.5.0",
"@react-navigation/bottom-tabs": "^5.x",
"@react-navigation/drawer": "^5.x",
"@react-navigation/native": "^5.x",
"@react-navigation/stack": "^5.x",
"@redux-offline/redux-offline": "^2.6.0-native.1",
"axios": "^1.2.2",
"lottie-ios": "3.4.0",
"lottie-react-native": "^5.1.3",
"moment": "^2.29.4",
"patch-package": "^6.5.1",
"postinstall-postinstall": "^2.1.0",
"react": "18.0.0",
"react-native": "0.69.3",
"react-native-alarm-notification": "^1.8.0",
"react-native-background-fetch": "^4.1.7",
"react-native-background-timer": "^2.4.1",
"react-native-geolocation-service": "^5.3.1",
"react-native-gesture-handler": "^2.7.0",
"react-native-keyboard-aware-scroll-view": "^0.9.5",
"react-native-maps": "^1.3.2",
"react-native-modal": "^13.0.1",
"react-native-pager-view": "^6.0.1",
"react-native-paper": "^5.2.0",
"react-native-permissions": "^3.6.1",
"react-native-reanimated": "^2.10.0",
"react-native-render-html": "^6.3.4",
"react-native-safe-area-context": "^4.4.1",
"react-native-screens": "^3.18.0",
"react-native-snackbar-material": "^1.0.0",
"react-native-tab-view": "^3.2.1",
"react-native-vector-icons": "^9.2.0",
"react-redux": "^7.2.5",
"redux": "3.7.2",
"redux-devtools-extension": "^2.13.9",
"redux-logger": "^3.0.6",
"redux-offline": "^2.0.0",
"redux-persist": "^6.0.0",
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"@babel/core": "^7.12.9",
"@babel/plugin-proposal-async-generator-functions": "^7.18.6",
"@babel/runtime": "^7.12.5",
"@react-native-community/eslint-config": "^2.0.0",
"babel-jest": "^26.6.3",
"babel-plugin-root-import": "^6.6.0",
"babel-plugin-transform-remove-console": "^6.9.4",
"eslint": "^7.32.0",
"jest": "^26.6.3",
"jetifier": "^2.0.0",
"metro-react-native-babel-preset": "^0.70.3",
"react-test-renderer": "18.0.0"
},

  • Plugin version:
  • Platform: Android: 12
  • Device manufacturer and model: Vivo 1938

Context

Expected Behavior

It should give the right speed. Like if device stays still, speed should be 0.

Actual Behavior

Possible Fix

Steps to Reproduce

async function initBackgroundGeolocation() {
BackgroundGeolocation.configure({
desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY,
stationaryRadius: 10,
distanceFilter: 10,
notificationTitle: 'Background tracking',
notificationText: 'ok',
debug: false,
startOnBoot: false,
stopOnTerminate: true,
locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER,
interval: 10000,
fastestInterval: 5000,
activitiesInterval: 10000,
stopOnStillActivity: false,
maxLocations: 1000,
url: '',
postTemplate: {
latitude: '@latitude',
longitude: '@longitude',
time: '@time',
bearing: '@bearing',
altitude: '@altitude',
accuracy: '@accuracy',
provider: '@Provider',
speed: '@speed',
},
startForeground: false,
});
}

const onLocation = location => {
console.log('location', location);
const odometer = convertSpeed(location.speed ?? 0); // speed * 18 / 5
setOdometer(odometer);
setIsMoving(odometer >= 15); // speed over 15km/h means moving
setLocation(location);
};

BackgroundGeolocation.on('location', onLocation);

Context

I tried to get speed so to know whether my device is moving. However I usually get incorrect value.

Debug logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions