# Thread: Fixing GPS Accuracy by applying Math

1. ## Fixing GPS Accuracy by applying Math

To all,

When plotting lines on a map, everything is okay, as long as the user is actually moving, and thus,
The problem usually starts when going inside. A global idea of where the user is still remains, but the accuracy of the fix drops insanely, and frequently deviates up to 50 meters from its actual location.

For example:

The blue line indicates a user driving in a car, reaching its destination.
All is fine, until the user goes inside a building, and a whole knot of plotlines is being drawn as a result.
The green 'star' is the actual location, and the blue lines around it are the locations submitted while the user is inside. The red lines are submitted when the user is inside for a long time, all at the same place.
Now to the hard stuff.

Example two:

In figure 1, you can see a user virtually driving a straight line. Thus, the distance from the first point taken (the blue one) to each of its successors increases. So we could say, as long as the distance from the first location taken to each of their replacements increases, we can assume the user is moving and locations are accurate.

But, (figure 2) this doesnt go for instance, when a user is driving on a roundabout. Lets say, you drive around a corner; The first locations taken after the very first one, WILL indeed be further away than the first one. Though, when you go over 50% on the roundabout (or corner) the later positions might be CLOSER to the first one again, so using this method to detect irradicality would not suffice.

Then, figure 3, lets say the user is in the middle, and those lines drawn around him are all the result of being inside, none of them are actually "going" anywhere. Although one might be closer to the first one, and the other might be further, there is no real way to tell whether this is data we want or not.

I've been breaking my brain on this for weeks now, took a holiday, and couldnt stop thinking about it.

Note: I think it would be unwise to calculate distances on the device all the time, cos it might eat your battery. This -MIGHT- be done serverside, so dont hesitate to come up with something extremely heavy and difficult.

Distance calculation between lat/lon's in javascript on nokia devices:
Code:
```	getDistance: function(lat1, lng1, lat2, lng2, miles) {
var pi80 = Math.PI / 180;
lat1 *= pi80;
lng1 *= pi80;
lat2 *= pi80;
lng2 *= pi80;

var r = 6372.797; /* mean radius of Earth in km */
var dlat = lat2 - lat1;
var dlng = lng2 - lng1;

var a = Math.sin(dlat / 2) * Math.sin(dlat / 2) + Math.cos(lat1) * Math.cos(lat2) * Math.sin(dlng / 2) * Math.sin(dlng / 2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
var km = r * c;

return (miles ? (km * 0.621371192) : km);
}```
Let's make this a follow up discussion.

Thanks,

Jasper

2. ## Re: Fixing GPS Accuracy by applying Math

Hello there, Jasper!

Thank you for an interesting article indeed. You really have been digging into this area.

WLAN to the rescue...?

Comments, ideas, suggestions related - anyone?

Best Regards,

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•