Android GPS Coordinates Scattered

做~自己de王妃 提交于 2019-11-28 07:50:43
kaushal trivedi

What you are getting is because your criteria identifies best provider as NETWORK_PROVIDER. Which does not identify your location but instead gives you the location of the cell tower whose range covers your device.So when you are outside of any building it is better to use GPS_PROVIDER to get fine accuracy of Geo locations.Why you get scattered co-ordinate is because your device comes to range of another cell tower hence location jump happens. Directly use GPS_PROVIDER is the best solution you will ever get.

The GPS data itself is prone to errors. Even if you have all the LocationManager set correctly (and it looks like you do) you will be seeing occasional jitter in the locations.

Accuracy

One thing to note is that the GPS accuracy only gives you an estimate to how good the calculation was given the GPS signals received. Systematic errors can give you a good accuracy number (<10m) but still represent a large position error. This is why you will see the jitter even if your accuracy is very good. Accuracy measures are good to remove very large errors (>100m) but on a lower level it just gives you an indication that the calculations converged.

Filtering

Filtering, like many things, is best if you do as little as possible. An accuracy filter should be able to remove large errors and if you end up with a good threshold you might be able to get smooth data.

You might also get some benefit if you put a threshold on position changes for running apps. For instance a runner can only cover a certain distance over time and by setting an upper threshold (Usain Bolt Cutoff) you should be able to remove bad points. The problem with that is that if your first point is the error you end up removing all the other points.

Kalman Filter

The Kalman Filter is a great solution and I have implemented it on navigation app that I am working on. The results are very reasonable and it even allows for limited dead-reckoning in the cases where GPS is bad or unavailable. Unfortunately I can't share the source code but I can give you a little guidance if you decide to go that way. The best results have come from a 6 DoF filter where you calculate acceleration and velocity and use that to estimate positions. It isn't the simplest solution but we have seen good results from it.

Least-Squares

The Kalman Filter is great since it can be used in realtime to filter the positions. It keeps track of its own state and you don't need to store old locations. But on the other hand if you want to post-process your route, least-squares fit is an optimal way to go. (Kalman is derived from the LSQ formulas). I don't do a lot of post-processing but I suspect I can dig up some old textbooks on it. The theory should be the same however.

Most GPS devices are pretty good and from all the testing I have seen I don't often see the jitter you are seeing in your example. However, one big advantage and the reason why I implemented the Kalman Filter is that your distance traveled and velocity calculations are much more accurate

Check this article of Reto Meier (code included). It should gives you lot of information to think about. You should at least set minimum distance and time parameters.

lm.requestLocationUpdates(lm.getBestProvider(criteria, true), 5000, 20,
        locationListener);

Also you can combine several providers to get best coordinates you can at the moment. Good luck!

A simple approach is to throw away any old or inaccurate data and keep a running average of the longitude and latitude.

private static final long WILDLY_OUT = 15;
private static final long TOO_OLD = 30000;
private static final long NO_SAMPLES = 5;

double lastLocationTime;

double calclongitude(Location location, double oldLongitude) {
    double newLongitude = oldLongitude;

    if (location.getAccuracy() < WILDLY_OUT) {
        newLongitude = (NO_SAMPLES * oldLongitude + location
                .getLongitude()) / (NO_SAMPLES + 1);
        lastLocationTime = System.currentTimeMillis();
    }

    if (lastLocationTime > TOO_OLD) {
        newLongitude = location.getLongitude();
    }

    return newLongitude;
}

And do the same for latitude.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!