Eddwhis
Eddwhis

Reputation: 1154

Android google maps - make polyline more straighter /smoother

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

Upvotes: 0

Views: 4684

Answers (1)

alvi
alvi

Reputation: 2702

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

Upvotes: 2

Related Questions