Location Change Glitches On Map Using Polyline Options
Im facing some problem with my application, specifically with route plot/draw on my google maps. Ive made test route around my house and found out, that GPS providers are not as ac
Solution 1:
First of all, you need to take into account the accuracy of the received location. You can get the accuracy using the Location.getAccuracy()
method (documentation). The accuracy is measured in meters, so the lower the better:
if (location.getAccuracy() < MINIMUM_ACCURACY) {
// Add the new location to your polyline
}
You can set your MINIMUM_ACCURACY
to be 10 meter for example.
On the other hand, you may want to add a new location to your polyline only if your new location is farther than a given distance to your last added location. As an example:
privatestaticfinalfloatMINIMUM_ACCURACY=10;
privatestaticfinalfloatMINIMUM_DISTANCE_BETWEEN_POINTS=20;
private Location lastLocationloc;
// ...publicvoidonLocationChanged(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;
}
}
}
Post a Comment for "Location Change Glitches On Map Using Polyline Options"