0
votes

I am creating app to draw my walking path by GPS. Everything is okay, path is drawing when I walk, but I have one question - it is possible somehow to make path line straighter programmatically?

For example. First, after walking I see my path like this(it is not polyline, it is polygon in example, but I think you will get the idea): https://www.dropbox.com/s/763mq0wja6x7lpy/11.png

But after saving, app made path more straighter/smoother: https://www.dropbox.com/s/npwkz9coqve7m4g/22.png

How to do this? Because I don't have any idea.

I am drawing path with LocationListener:

LocationManager locationManager = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);

    Criteria criteria = new Criteria();
  //criteria.setPowerRequirement(Criteria.POWER_LOW); 
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setCostAllowed(true);
    criteria.setSpeedRequired(false);       
    String bestProvider = locationManager.getBestProvider(criteria, true);
    locationManager.requestLocationUpdates(bestProvider, 500, 3, this );

And onLocationChanged listener:

@Override
public void onLocationChanged(Location location) {

          if(lastLocationloc == null) 
                          lastLocationloc = location;     
          LatLng lastLatLng= locationToLatLng(lastLocationloc);
          LatLng thisLatLng= locationToLatLng(location);
          mMap.addPolyline
                       (new PolylineOptions().add(lastLatLng).add(thisLatLng).width(4).color(Color.RED));
          lastLocationloc = location;             
  }
1
Not sure but i'd guess its just because of your lastLatLng and thisLatLng. Lat and long info is always a little shaky, so if you use this as straight input to drawing a line...the line will be shaky. You could try to adjust your latlong info a little to decrease noise, but this might be tricky. - Stefan de Bruijn
What do you mean by saying "adjust your latlong" ? - Eddwhis

1 Answers

2
votes

The LocationManager will never give you exact locations. Therefore, while you may not be walking in a non-smooth way, the GPS coordinates you get will always be jumpy, even if you set a very high accuracy in your Criteria.

So, when you draw the path, you may consider using Android's Path API

For some code on this, look at this answer:

Android How to draw a smooth line following your finger