i want to draw path on google map.
Basically what i am tracking user locaion after specfic time interval. when user reach to some destination then i need to draw the
The problem is not on your drawing function but on the method you are using to get the points of your path using the received location.
You need to take into account two factors:
Location.getAccuracy()
method (documentation). The accuracy is measured in meters, so the lower the better.An example combining both considerations:
private static final float MINIMUM_ACCURACY = 10; // If the accuracy of the measurement is worse than 10 meters, we will not take the location into account
private static final float MINIMUM_DISTANCE_BETWEEN_POINTS = 20; // If the user hasn't moved at least 20 meters, we will not take the location into account
private Location lastLocationloc;
// ...
public void onLocationChanged(Location mylocation) {
if (mylocation.getAccuracy() < MINIMUM_ACCURACY) {
if (lastLocationloc == null || lastLocationloc.distanceTo(mylocation) > MINIMUM_DISTANCE_BETWEEN_POINTS) {
// Add the new location to your polyline
lastLocationloc = mylocation;
}
}
}