Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the suggested way of implementing overlays in v2 of the Android Google Maps API?

In the original version of the Android Google Maps API it was very easy to implement an overlay with the following code:

List<Overlay> mapOverlays = mapView.getOverlays();
AlarmOverlay alarmOverlay = new AlarmOverlay();
mapOverlays.add(alarmOverlay);

...it was then possible to override the overlays draw() method and paint vector graphics, override the overlays onTouchEvent() method and give custom controls, etc.

I am at a loss as to how to architect similar custom controls in v2, as the use-case for overlays is not mentioned in the API reference (and markers and polygons are not enough). Does anyone have a suggested way of implementing in v2?

like image 810
gsysko Avatar asked Dec 31 '12 19:12

gsysko


1 Answers

If you need to place your own image on the surface of the earth, use GroundOverlay. The method addGroundOverlay adds such image. It takes GroundOverlayOptions that allow to specify the image size and location (in lat long terms) and also BitmapDescriptor that, among other options, can use the ordinary Bitmap as the image source. So you can create a new Bitmap, create Canvas around this bitmap and paint there.

Seems a good approach if you need to draw something really complex, something for that polygons and markers are not sufficient. Also, the old code that draws on Canvas probably can be reused.

I have not done enough testing how soon the map will be updated after we update the bitmap. In the worst case, maybe the ground overlay needs to be removed and the new ground overlay added. The bitmap itself probably still can be reused.

Putting additional component on the top may be problematic as it must support zooming, moving around and the map is now even 3D.

like image 165
Audrius Meškauskas Avatar answered Nov 15 '22 22:11

Audrius Meškauskas