Note that there are some explanatory texts on larger screens.

plurals
  1. PODraw a route using current location from device on map using GPS Provider
    primarykey
    data
    text
    <p>I'm working on a project to display a route in a <code>MapView</code> based on current location from <code>GPS</code> Provider. I'm able to draw the path between two points but the problem starts when the location changes to a new point causing the draw path to erase. </p> <p>Basically my Location Listener saves the current <code>GeoPoint</code> and sets the new <code>GeoPoint</code> location and after that it starts the overlay to draw a path based on those two points.I think an option could be saving the coordinates to a database and then pulling the information from there to draw the path. </p> <p>Here is my code so far:</p> <pre><code>private class MyLocationListener implements LocationListener { public void onLocationChanged(Location location) { Toast.makeText(getBaseContext(), "Tracking device..", Toast.LENGTH_SHORT).show(); gp2 = new GeoPoint( gp1.getLatitudeE6(), gp1.getLongitudeE6()); gp1 = new GeoPoint( (int) (location.getLatitude() * 1000000), (int) (location.getLongitude() * 1000000)); myOverlay = new MapOverlay(); mapOverlays_route.add(myOverlay); myMapView.invalidate(); } } class MapOverlay extends com.google.android.maps.Overlay{ public MapOverlay(){ } public void draw(Canvas canvas, MapView mapv, boolean shadow){ super.draw(canvas, mapv, shadow); //Configuring the paint brush Paint mPaint = new Paint(); mPaint.setDither(true); mPaint.setColor(Color.RED); mPaint.setStyle(Paint.Style.FILL_AND_STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(4); Point p1 = new Point(); Point p2 = new Point(); Path path1 = new Path(); Path path2 = new Path(); projection.toPixels(gp1, p1); projection.toPixels(gp2, p2); path1.moveTo(p2.x, p2.y);//current location path1.lineTo(p1.x,p1.y);//new location canvas.drawPath(path1, mPaint);//drawing the path } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload