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; }
lastLatLngandthisLatLng. 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