An Overlay is an imaginary layer above the MapView where it is stored in the MapView’s data structure (gettable via MapView.getOverlays()).
Why do we want to use Overlay?
1) We want to put stuff on a map (e.g., a mark, a route, text);
2) We want to get touch event before the MapView does (so that we can, say, override the pan & zoom operation).
Step 1. Create a class that extends Overlay (or its subclasses)
Here is a step-by-step tutorial. To get a holistic idea, an overlay class primarily overrides the following methods so that we can do something on this imaginary layer:
draw(...), drawAt(...), onKeyDown(...), onKeyUp(...), onTap(...), onTouchEvent(...), onTrackballEvent(...), ...
Step 2. Put that class into the MapView’s Overlay List
This usually happens in your onCreate method. After the usual initialization of the map, we first get MapView’s List of Overlays:
List<Overlay> mapOverlays = mapView.getOverlays();
We then create an instance of our Overlay class, called myOverlay; then we simply add this object to the List:
The effect of this Overlay depends on how many methods you have overridden in your Overlay class. For example, if you have overridden onTouchEvent(), then the MapView’s default pan & zoom no longer works.