I am trying to draw polylines while i'm walking/driving(connecting point by point) but it comes out messy(Image link). I read the recommendations here and did some research, and I came up with the below code to do that:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment supportMapFragment = (SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.map);
googleMap = supportMapFragment.getMap();
googleMap.getUiSettings().setCompassEnabled(false);
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
googleMap.setMyLocationEnabled(true);
}
I start from the initializeDraw() first:
private void initializeDraw(){
rectLine = new PolylineOptions().width(5).color(Color.RED);
newPolyline = googleMap.addPolyline(rectLine);
}
And than I start the OnLocationListener (using network_provider):
RTlocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, drawLocationOnMap);
The locationListener (from which i'm updating the points(lat/lng and focusing the cam on the location):
LocationListener drawLocationOnMap = new LocationListener() {
public void onLocationChanged(Location location) {
LatLng newPoint = new LatLng(location.getLatitude(), location.getLongitude());
points = newPolyline.getPoints();
points.add(newPoint);
newPolyline.setPoints(points);
CameraPosition cameraPosition = new CameraPosition.Builder().target(new LatLng(location.getLatitude(), location.getLongitude()))
.zoom(18)
.bearing(0)
.tilt(70)
.build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
};
};
The result:
Image link
By looking at the image above, it looks like a "zigzag" even though I walked a straight 100m line . Any help on this will be much appreciated.