A Basic LocationSensor Speedometer

A Basic LocationSensor Speedometer

An app with an analog speedometer display using a GoogleCharts gauge and javascript. This example works on an Android 8.1 and probably all Androids between 5 and at least 8.1 .

There are two speedometer dials; 0 to 100 mph and 0 to 50 mph. Modify the html files stored in Media to set different display ranges. ( Make an Analog Gauge and use it to display something useful . shows an Altimeter gauge; you can instead plot km/hr or miles/hr by adapting the Blocks).

For a larger display you might set Sizing from Responsive to Fixed on the Designer Screen Properties.

Be aware, the LocationSensor determined speed is not instantaneous. The GPS receiver must receive at least two LocationChanged events before it is capable of displaying speed. This delay can take 30 to 60 seconds or more after the app is 'turned on.'


Don't run into a tree while you are watching your Android display. The speed updates in the example every 20 seconds. Speed is not instantaneous; the app takes a few seconds to calculate and requires a LocationChanged event.


A calculation of speed when using the speed property requires that the LocationSensor capture two separate satellite fixes and two LocationChanged events. The sensor cannot calculate instantaneous velocity. The LocationSensor needs to location points and calculates the distance between them and the time. The LocationSensor has to have a history of at least two separate location points to calculate the speed.

The LocationChanged(number latitude, number longitude, number altitude, number speed) event of the LocationSensor detects when a new location has been detected. It is called when the Android device reports a new location.

speed units - the LocationSensor reports speed in m/sec units), convert to km/hr if you want speed in kilometers (1000 meters) and also be aware m/sec must be addressed to convert kilometers/hour. m/sec * km/1000m * 60 sec/min * 60 min/hour = km/hour . To convert m/sec to mph, Multiply the rate of meters per second by 2.2369. Example: 30 meters per second times 2.2369 equals 67.107, so 30 meters per second equals 67.107 miles per hour.

Speed has a second component, the TimeInterval ... how frequently you update the LocationSensor to determine a satellite fix. The initial satellite fix usually takes about 30-40 seconds; subsequent satellite fixes dependent on factors discussed in the tutorial Using the Location Sensor take at least 10 to 20 seconds . How frequently the LocationSensor updates depends somewhat on how good (sensitve) a GPS receiver is in your Android. It makes little sense to set the TimeInterval to less than about 20000 ms (20 seconds). You might have luck with 1 second TimeInterval on some devices. This means, the speed will update at the best, every 20 seconds if even that.

Be aware

Your GPS hardware location is not precise (see Using the Location Sensor) the speedometer will often display an 'erroneous' speed when you are at rest (not moving) or moving at low relative speeds. This means the speedometer will not display 0 when you are not moving unless you provide code Blocks to force a zero indication. If speed > 0.5 as shown in the example then code to do something will partially work to display 0 (provided the present Accuracy and previous Accuracy is a small value).

If you are not moving; believe what you see around you and not the speed indicated on the speedometer. Don't use this app to replace your vehicle's speedometer.

I hope someone finds this example useful. :slight_smile:

SpeedometerGauge.aia (47.0 KB)



Will it be disadvantageous to change the refresh rate to a smaller interval, around 5 seconds; not too less, however, to give it some buffer time?

You can try a smaller TimeInterval than 20 seconds. How small a value you use that will consistently work depends on your device gps hardware. With my device 20 seconds almost always works.

What is at issue is how sensitive the gps receiver might be and how fast it can achieve subsequent satellite fixes.

Let us know what you discover.

1 Like

I was testing just as you were typing this, and discovered....
...everything less than ~10 seconds possibly an inaccurate estimate) returns 0, because <=0.5mph is hardcoded to 0mph.

In hindsight, I should've tested before asking.


  • 0.5 mph is 0.733 ft/sec.

  • in 10 seconds, the device would possibly move 7 feet

  • the best precision most gps receivers in cell phones have is the ability to resolve at best 2 meters (6.6 feet) (some of the newest hardware can resolve to several feet, but mine cannot).

  • Accuracy (the ability to estimate the reliability/quality of the information received from the satellites) continually varies. If the Accuracy is 10 that means your actual location is not where you think it is but within the reliability circle of 10 meter diameter. (although it might actually be where it thinks it is :astonished: )

Have fun but be aware, working with a gps complex although the LocationSensor tool makes it seem simple. :cry: