Detecting "unlikely" places in an app similar to Google Location History
I am currently writing a small geolocation application similar to Google Location History . The android phone regularly sends its position to the server and I can show them on the map. I am using JavaScript API 3 and it works quite well. However...
As you can see, something is wrong: sometimes the location is extremely inaccurate, possibly due to telephone switching networks. I would like to get rid of these "bad places" to show a clean path, and I have not yet figured out how to do this.
How do you determine if a location is clearly false?
This is pretty obvious from a human point of view, unfortunately my computer doesn't think about it yet.
-
One solution would be to use the
computeHeading(from:LatLng, to:LatLng)
from functiongoogle.maps.geometry.spherical
to detect very sharp corners in quick succession and act accordingly; however, I don't know how to do this, as checking the last five points each time seems like it would be a little ineffective ... especially since I have several thousand points to deal with. -
Another thing might be to estimate the speed of movement and ignore points with sudden and unrealistic acceleration.
-
Perhaps I can check if the point is within the area defined by its neighbors. It seems reasonable to assume that each position should be somewhere between the previous and the after, as in the example below.
Any help would be appreciated.
source to share
So, I decided to go with the third method I was thinking about: testing if the marker is in a circle defined by two other markers. Basic geometry, Pythagorean theorem. Here's my code:
function isLikely(testedPos, pos1, pos2) {
var hypothenuse = calcDistance(pos1, pos2);
var side1 = calcDistance(testedPos, pos1);
var side2 = calcDistance(testedPos, pos2);
if (hypothenuse*hypothenuse*1.2 >= side1*side1 + side2*side2)
return true;
else
return false;
}
calcDistance
is just an alias for google.maps.geometry.spherical.computeDistanceBetween()
. Because I'm lazy.
It works great!
source to share