简体   繁体   中英

Writing javascript to detect speed

I am a new member. For school, they want us to write code to figure out the speed of the device (when driving). Is this possible in javascript? Im assuming it will be challenging but any ideas help! Thank you in advance!

You can use Geolocation API to get current position.

Since speed is distance over time, you can use a setInterval() to periodically get the position (every 3 seconds for example) and calculate the distance between the last and current coordinates .

Since that's a homework/school work, I think I shouldn't give you any code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM