The problem I believe is well known.
So what is my problem?
I am writing an app that is using the GPS provider to find the location of the user and calculate the distance from the user to the end point. This works correctly. However a problem occurs:
The problem in details:
If you go around the city with my app it will give you some numbers for your distance but ... the distance is aways changing. No matter if I move towards my destination the distance either goes higher or goes lower (the value of the distance calculated is "jumping" around from high to low and vise versa) the the previous number of the distance but logically it should be getting lower. I believe this is because the GPS signal is sometimes lost or weak and it cant calculate the distance correctly.
What I need help with?
I want to know is there a way to filter the coordinates received from the GPS so I can get more accurate numbers for distance so when I move towards my end point the distance is calculated correctly(as possible not necessary to be 100% correct) and not go up and down the scales like crazy.
How do I get the coordinates and calculate the distance:
public void onLocationChanged(Location location)
{
txtLat = (TextView) findViewById(R.id.currentCoordinatesView);
clat = location.getLatitude();
clong = location.getLongitude();
Location location1 = new Location("Start");
location1.setLatitude(clat);
location1.setLongitude(clong);
Location locationB = new Location("Finish");
locationB.setLatitude(endLatitude); //endpoint coordinates
locationB.setLongitude(endLongitude);
distance = location1.distanceTo(locationB); //calculate the distance
TextView TextDistance = (TextView)findViewById(R.id.TextDistance);
TextDistance.setText(new DecimalFormat("##,###,###.##").format(distance)+" m");
CurLat = location.getLatitude();
CurLong = location.getLongitude();