[Android Q&A, Help & Troubleshooting] oandroid:
I am developing an application which draws the path of the user as he moves and calculates the area .

This is the code i am trying my problem is at the start of recording the path the path is drawn even if the user has not moved and sometimes when even if user is moving the path is not drawn .

RouteOverlay class:

public class RouteOverlay extends Overlay {

private GeoPoint gp1;

private GeoPoint gp2;

private int mode = 1;

public RouteOverlay(GeoPoint paramGeoPoint1, GeoPoint paramGeoPoint2,int paramInt)

{

this.gp1 = paramGeoPoint1;

this.gp2 = paramGeoPoint2;

this.mode = paramInt;

}

public void draw(Canvas paramCanvas, MapView paramMapView,

boolean paramShadow)

{

super.draw(paramCanvas, paramMapView, paramShadow);

Projection projection = paramMapView.getProjection();

Paint mPaint = new Paint();

mPaint.setDither(true);

mPaint.setAntiAlias(true);

mPaint.setColor(Color.RED);

mPaint.setStyle(Paint.Style.FILL_AND_STROKE);

mPaint.setStrokeJoin(Paint.Join.ROUND);

mPaint.setStrokeCap(Paint.Cap.ROUND);

mPaint.setStrokeWidth(3);

mPaint.setAlpha(120);

Point p1 = new Point();

Point p2 = new Point();

Path path = new Path();

projection.toPixels(gp1, p1);

projection.toPixels(gp2, p2);

path.moveTo(p2.x,p2.y);

path.lineTo(p1.x,p1.y);

paramCanvas.drawPath(path, mPaint);

}

MainActivity:

public class MainActivity extends MapActivity {

public final LocationListener locationListener = new LocationListener() {

public void onLocationChanged(Location location) {

coordinates.add(location);

mapView.getController().animateTo(getGeoByLocation(location));

drawRoute(coordinates, mapView);

}

};

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_area_measurement);

this.mapView = ((MapView) findViewById(R.id.mapview));

this.mapView.setBuiltInZoomControls(false);

this.mapView.getController().setZoom(17);

this.coordinates = new ArrayList<Location>();

}

protected boolean isRouteDisplayed() {

return false;

}

private GeoPoint getGeoByLocation(Location location) {

GeoPoint gp = null;

try {

if (location != null) {

double geoLatitude = location.getLatitude() * 1E6;

double geoLongitude = location.getLongitude() * 1E6;

gp = new GeoPoint((int) geoLatitude, (int) geoLongitude);

}

} catch (Exception e) {

e.printStackTrace();

}

return gp;

}

public String getLocationProvider(LocationManager paramLocationManager) {

try {

Criteria localCriteria = new Criteria();

localCriteria.setAccuracy(1);

localCriteria.setAltitudeRequired(false);

localCriteria.setBearingRequired(false);

localCriteria.setCostAllowed(true);

localCriteria.setPowerRequirement(3);

String str = paramLocationManager.getBestProvider(localCriteria,

true);

return str;

} catch (Exception localException) {

while (true) {

localException.printStackTrace();

}

}

}

private void drawRoute(ArrayList<Location> paramArrayList,MapView paramMapView) {

List<Overlay> overlays = paramMapView.getOverlays();

//Changed for smooth rendering

overlays.clear();

for (int i = 1; i < paramArrayList.size(); i++) {

overlays.add(new RouteOverlay(getGeoByLocation(paramArrayList.get(i - 1)), getGeoByLocation(paramArrayList.get(i)),2));

}

}

public void startRecording() {

this.isMeasuring = true;

lm = (LocationManager) getSystemService(LOCATION_SERVICE);

lm.requestLocationUpdates(getLocationProvider(lm),500,2,this.locationListener);

/*if (lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){

gpsstatus.setText("Gps Is Enabled");

}else

{ gpsstatus.setText("Gps Is disabled");}*/

}