I want to create a functionality like Google Maps. I want to update my location marker whenever a person start walking/driving. I am thinking of using onLocationChange metho
Current location can be easily drawn with MyLocationOverlay. What you need to do - is to add this overlay to your MapView. Something like:
mapView.addOverlay(new MyLocationOverlay(context, mapView));
The default location dot will be drawn automatically and will be updated as soon as you move
With route it is a bit trickier, but still there is no rocket science in there. What you need to do - is to extend Overlay class and implement draw()
logic. You need to keep track of GeoPoints you travelled and project them on a map (in your overlay's draw()
you can ask your mapView for a Projection
instance - getProjection()
. You can use this projection to map GeoPoints to your map coordinates).
As soon as you have list of GeoPoints - you can create a Path and draw this Path on a Canvas
The simplified example how to draw path on a map (there are some custom classes I use in my project, but you should get an idea):
Path path;
@Override
public void draw(Canvas canvas, final MapView mapView, boolean shadow)
{
Projection proj = mapView.getProjection();
updatePath(mapView,proj);
canvas.drawPath(path, mPaint);
}
protected void updatePath(final MapView mapView, Projection proj)
{
path = new Path();
proj.toPixels(mPoints.get(0).point, p);
path.moveTo(p.x, p.y);
for(RouteEntity.RoutePoint rp : mPoints)
{
proj.toPixels(rp.point, mPoint);
path.lineTo(mPoint.x, mPoint.y);
}
}