Insights & Advice

How to improve GPS use in your app

The average modern smartphone provides a wide array of technology that allows both native and web app developers to extend the functionality of their ideas beyond simple information consumption. Taking advantage of features like real world location data can bring a whole new experience layer to your ideas as well as enhance the relevance of your content. However, the basic concepts behind GPS can also be a major pitfall when developing an app centered around them.

Image by Samuel Foster

GPS: A brief introduction

Before we take a look at how location readings can begin to break down we need to understand the basics of how the global positioning system works with your device to identify where you are on the planet.

The global positioning system (GPS) is made up of a large constellation of satellites orbiting Earth in a fixed position constantly emitting a unique signal. By picking up these signals devices like smartphones can tell how far each satellite is from it. As these satellites never move from their locations, devices can triangulate where they are based on the distances they record from each satellite.

Example of satellite distances triangulating location

What can cause GPS accuracy to break down?

While the concept seems rather straightforward there is a delicate balance of conditions that needs to be met to get an accurate location. Satellite signals can start to degrade in rough weather. Trees and buildings can obscure, block or even reflect satellite connections.

These fluctuations in signal quality affect how far your device thinks the satellite is and when added to its calculations it can often place you far from where you actually are.

Example of how signal degradation can affect calculated location

How GPS inaccuracy can affect your application development

On a large scale these fluctuations don’t make much of a difference but when working with fine grained location tracking this degradation of location accuracy can become a major issue for application development.

In this example your device location is regularly requested. When running on a device with GPS location enabled, you can remain completely still and your location appears to still move. In most areas this fluctuation is only a few centimetres but in some cases this can jump quite a long distance.

Easing GPS accuracy fluctuations with interpolation

In the most basic form, interpolation is just a way of easing a number from one value to another over time instead of jumping immediately to it.

const interpolate = (from, to, interpolation) => from + ((to - from) * interpolation);

console.log(interpolate(12, 42, 1));   // 42
console.log(interpolate(12, 42, 0.5)); // 27
console.log(interpolate(12, 42, 0.2)); // 18
console.log(interpolate(12, 42, 0));   // 12

By applying this to a coordinate that’s jumping around you start to get more meaningful data.

In the demonstration below, a coordinate is being randomized to simulate something like GPS inaccuracy. The exact same coordinate sees a lot less fluctuation by applying a little interpolation to it as it updates.

Balancing coordinate interpolation

Interpolation can be loosened and tightened depending on how much you want to reduce the noise in your coordinates. Although it might seem like you’d want to keep that as tight as possible, this can cause your coordinate tracking to lag far behind if the device actually starts moving as your application won’t be able to distinguish this from GPS inaccuracies.

This example demonstrates moving around with an inaccurate GPS signal. Interpolation can reduce the noise in this movement while still tracking it relatively well but amping that interpolation too high causes the tracking to lag significantly.

There is no “correct” level of interpolation as tracking fast movements need much lower levels than something tracking walking speeds. This level comes down to a bit of a trial and error depending on your use-case but even at lower levels of noise reduction you may find this approach makes your app a little more accurate.

This website uses cookies to improve your experience. By using Prism, you accept our use of cookies.