Location Sensor (Speed)

Hi Steve, thanks for your comments. TBH it wasn’t tested on a device and the text i’d written was basically sudo code. Having tried it on a device and gone through the blocks again, yes, there was a few logic errors and a few assumptions i’d made. I’ve gone back to the drawing board and after a bit or research and head scratching i think might just have cracked it… As requested here is the .aia file… Let me know your thoughts (I mean that genuinely, not being sarcastic :smiley: )

Speedo_v2(1).aia (37.4 KB)

EDIT: I’ve included some extra bits (in red) for diagnostics, obvs if you don’t want it, remove it… Same with the heading calculation & smoothing…

PS Have a play with the timing of the ‘SpeedTimer’…

PPS I haven’t tested it for accuracy, it’s more of a proof of concept, don’t shoot me if i’ve made an error in the math!

1 Like

@carto_lover
Try this simple as it gets code. Run the app while bicycling or riding in a vehicle. Standing still, it will indicate a speed because each successive satellite fix provides new but slightly different latitude and longitude calculations even though the gps receiver is not moving. The LocationSensor algorithm calculates the speed in meters per second. The app searches for a satellite fix every 20 seconds. This means you need to wait about a minute before the app will determine your average velocity between the two satellite fix geocoordinates. Convert the resulting mps as shown to mph (conversion factor of 2.23694) or convert to kph (conversion factor of 3.6) instead by modifying the Blocks.

Yes, this is that simple.

so... is there any way to develop a gps speedometer and work real time as all apps in play store? i just want to add it to my app and refreshes to slow... or i have to develop it with android studio?

hello, can you provide your project to study it? i try but i cant do it work in real time...

@JohnnieK Use the code shown in the #6 discussion.

No app using the GPS can work instantaneously using the constellation used by the LocationSensor. The gps using the LocationSensor takes 30 to 60 seconds to acquire it's first satellite fix and subsequent fixes might be possible each successive fix at up to 10000 ms intervals. To record speed, it takes the LocationSensor to report at least two successive satellite fixes. Read about this in LocationSensor .

You can try to set the TimeInterval to 1000 ms, with unpreditable results. The TimeInterval determines the minimum time interval, in milliseconds, that the sensor will try to use for sending out location updates. However, location updates will only be received when the location of the phone actually changes, and use of the specified time interval is not guaranteed. For example, if 30000 is used as the time interval, location updates will never be fired sooner than 30000ms, but they may be fired anytime after.

Values smaller than 30000ms (30 seconds) are not practical for most devices. Small values may drain battery and overwork the GPS.

How are you trying? Are you testing on a bicycle or in a car?

1 Like

i dont understand where is #6.... i am new to site :stuck_out_tongue: how other apps in play store get speed in real time?

motorcycle, i get a speed in a few seconds but when i increase speed i dont get the speed, only after a lot seconds... i saw with android studio a project and was "real time" results. to your code i see...19km........ after a lot of sec..... 45km....... after a while 70km

Change the IntervalTime to 1000 ms and see what happens. If you do not get an improvement, you are getting the best possible using the LocationSensor that is part of App Inventor.

Did you test it or is this a description of what they claim? The newest phones have the ability to use information from several satellite constellations. The MIT App Inventor 2 control does not. If you see an improvement using another app; do so. Instead of using LocationSensor, you might have a different result using one of the extensions that are 'replacement' controls (search here App Inventor Extensions | Pura Vida Apps . Will an extension provide a better result, I do not know.

The conversation for May 6 Johnnie has the code.

i see... the app from android studio was real time, like all speedometer apps in play store, i just dont know to use Studio, it was very complicated for me and the app i made is in MIT app... so i dont know how to join them :stuck_out_tongue: i ll try to minimize the ms and lets hope it works :slight_smile: thanks for your time

OK. Good luck. Let us know what you discover.

Can I know How did you make your speedometer? I tried the simplest one but it doesn't work!

Welcome Xinzhi.

What did you try? Explain what is not working?

How speed works is explained here> How do we measure our speed with location.(speedometer) and did you read the posts in this post in comment #10 ?


This is my code. I was trying to run a speedometer with a graph,but it doesn't work

I just wanna make a speedometer app for a bike something

Here are two ways to make a gauge (speedometer); one uses the Canvas another uses GoogleCharts Make an Analog Gauge and use it to display something useful. The example shows an Altimeter gauge; you can instead plot km/hr or miles/hr by adapting the Blocks.

Here is how the LocationSensor measures speed https://groups.google.com/g/mitappinventortest/c/OxxRsUWzwpw/m/-JlxAS49AwAJ .

Try some Blocks, if you still have issues ask again and you will get specific advice.

Some time ago I wrote an app as you describe using the Canvas. I will see if I can find the code.

1 Like

Hi aia Can you share the extension?
Thanks

Extension? None is needed, see A Basic LocationSensor Speedometer

If you want to try an extension LocationSensor, try searching App Inventor Extensions | Pura Vida Apps ; there are several.

2 Likes

Thank you brother

1 Like

this is an interesting problem to detect 0 velocity and i have no good solution to offer and also would need it in my app.
but i think the implementation of SPEED calculation is not perfected in the location sensor n appinventor and here is why i think so.
i used the location sensor speed information in parallel with my old garmin hiking GPS ETREX Vista HCx
first on the side i found a disturbing fact. the phone gives an altitude of 250 ft and garmin reads like 330ft. 330 is also what the topo map indicates, so phone altitude is off. not only in the appinventor also in other GPS app. my phone is a motorola G stylus

back to speed.
the garmin takes about 2 seconds to recognize i stopped walking. i can walk as slowly as 0.8 mi/h and it is still recognized as moving.
in my app it takes about 10sec or more to come to a 0 velocity reading and sometimes it NEVER reads 0 because it does not get a new trigger. i use the location change as trigger and the timer interval is set to 10000ms.
so clearly the garmin does an excellent job in measuring the velocity to very low speed and can quickly differentiate the stopping condition.
and the garmin uses in the conditions mentioned 8 satellites and the phone says it uses 16 out of 24 visible.
therefor i would say garmin has the better algorithm to measure speed and therefor it is possible to have a better 0 speed condition threshold. i mean to tell me within 2 seconds i am not moving is great.
i assume the gramin uses higher sampling rate and more averaging to get a better position fix.
garmin says its accuracy was 3-6 ft and phone had like 6-10m inaccuracy.

any comments?

thanks
erhard