Writing javascript to detect speed - javascript

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.

Related

How accurate and reliable is GeolocationCoordinates.speed API?

I was wondering how accurate and reliable is the property speed of a single sample of GeolocationCoordinates API.
I want to take few samples of the current speed of an object (with GPS) and I am not sure if I should calculate the velocity myself (by the distance traveled between two time samples using altitude, longitude and altitude), or just use the property speed of a simple GeolocationCoordinates sample.
How does the speed property is being measured?
Which approach should I take?
The GeolocationCoordinates.speed read-only property is a double
representing the velocity of the device in meters per second.
source, also this might help
So I guess you don't have to calculate it manually.
TIP: For better accuracy, make sure the device is not in battery save mode, as it affects the result a lot.

JS/Web Audio: How do I jump to loopStart immediately, while playing?

I'm working with the Web Audio API in javascript.
Part of my current project involves a looper, I need to change the start and end points of the looper dynamically. Which is working.
But I need the playback position of the audio file to move to the start point when I set it. I've been googling and reading the spec for days, but I can't seem to find an answer.
I know you can set it with the start() function, but I need to change it while it is already playing.
Thanks!
If I understand what you're trying to do, I think the only way to do this is to create a new AudioBufferSource using the same buffer. Adjust this new AudioBufferSource with the same loop points as the original and then call start() with the correct start time and offset.

How does google's position.coordinates.speed translate into mph?

I've been messing around with Google Maps API. It returns a position object, with relevant bit being the following:
{
"speed": 1.41837963
}
I have a number of readings from driving around the block ranging from -1, 0 (understandable since I was just sitting there) to about 19~. It seems about right considering how I was driving but how does this translate into approximate mph?
I'm assuming your not using Google Maps to obtain the user's position, but instead using the W3C Geolocation standard. Speed is given in meters/second, so to convert to MPH just multiply the returned value by 2.23694.
If your code contains something like navigator.geolocation.getCurrentPosition() or navigator.geolocation.watchPosition(), then speed is given in m/s. If, however, the above methods don't look familiar, post your code, or the endpoint you're requesting and I'd be more than happy to try to get you sorted out.
I was unable to find any documentation on google maps api position object in relation to speed, but you can calculate the speed yourself given two sets of gps coords.
Here is a link on how to do this in Java but the idea's will be the same.
http://www.ridgesolutions.ie/index.php/2013/11/14/algorithm-to-calculate-speed-from-two-gps-latitude-and-longitude-points-and-time-difference/
That way you are doing the calculations yourself and not relying on someone else to do it for you.

JS that shows FPS for JS and CSS3 animations

I'm doing a series of tests (small study) to see the difference in fluid animation (by measuring Frames per second) between using JS to animate an object or JS with CSS3 doing the animating.
I've already found some solutions for getting FPS counter (meter) in JS, but I need to call it every time whenever I call the render function. This would be alright if the animating is done purely on javascript part. If I decide to move from animating using JS to CSS3, to my knowledge there is no way to detect how fast that transaction will be.
I know that for webkit browsers (tested in Chrome) I can get such info through developer tools, but since I will be testing also on other platforms I'm looking for a universal solution.
Any ideas, suggestions, anything that points me into right direction is appreciated. Thanks.
So I have found out the solution. It's called FPSMeter and it was developed by David Corvoysier. You can find the library and more about it here.
Basically he came up with a good idea, to simply append 1 CSS animated element in the body of the page. Then he uses transitions to animate that element and on every requestAnimationFrame he tries to calculate computed position of that element. On every second he then simply counts the number of different positions occupied by the element. Based on that he obtains FPS.

Display 2 cursors at the same time using Javascript

I'm actually working on a video conferencing project and I was wondering if there is any way to display 2 cursors at the same time based on mouses' position of the 2 guys talking to each other?
Basically, they gonna share the same screen, but I want one to be able to see the mouse pointer of the other one since they gonna work on common exercice.
Thanks for the help
Wouldn't it be easiest to have a div element with a custom mouse cursor that you move around in JavaScript by the coordinates received from the other user?
I think having two equal-looking cursors would just cause confusion.

Categories