Agontuk / react-native-geolocation-service

React native geolocation service for iOS and android
https://www.npmjs.com/package/react-native-geolocation-service
MIT License
1.61k stars 291 forks source link

[Not a bug] - ask about caculate speed and coords.speed #331

Closed WindCrafter closed 2 years ago

WindCrafter commented 2 years ago

Environment

Binaries: Node: 14.17.0 - /usr/local/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 6.14.13 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Managers: CocoaPods: 1.10.1 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4 IDEs: Android Studio: 4.2 AI-202.7660.26.42.7351085 Xcode: 12.5/12E262 - /usr/bin/xcodebuild

Platforms

Android, IOS

Versions

Description

I use Geolocation.watchPosition to get location information, specifically, I need to get device speed using coords.speed info but i don't know if the unit to use is m/s or km/h, or the way this information is calculated could lead to bias. When I check it, it doesn't match the real speed. So someone tells me how can I use coords.speed or algorithm to calculate speed. Thanks you,

alalbuquerque22 commented 2 years ago

I also couldn't understand how this speed is calculated, it's really not clear if it's meters/seconds or meters/hour or kilometers/hour or miles/hour.

one way to calculate the speed is to use the haversine formula (last latLong, current latLong) this will return the distance traveled, after this, you must calculate the distance divided by the time and so you will get the speed

Agontuk commented 2 years ago

https://developer.apple.com/documentation/corelocation/cllocation/1423798-speed [https://developer.android.com/reference/android/location/Location#getSpeed()](https://developer.android.com/reference/android/location/Location#getSpeed())

It's meter per second for both platform. The library is not doing any calculation, it just returns the value provided.

Agontuk commented 2 years ago

Closing this as this is not an issue.