Categories
discuss

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 mapOverlays = mapView.getOverlays(); AlarmOverlay …

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?

Answer

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.

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..