什么是Android的谷歌地图API V2实施覆盖的建议的方法是什么?建议、地图、方法、Android

2023-09-05 10:35:47 作者:骄傲旳厷主

在Android的谷歌地图API的原始版本是很容易实现具有以下code覆盖:

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);

......就在那时可能重写覆盖draw()方法和油漆矢量图形,重写覆盖的onTouchEvent()方法,并给自定义控件,等等。

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

我很茫然,如何建筑师在v2中类似的自定义控制,因为用例为覆盖在API引用没有提到(和标记和多边形是不够的)。有没有人有实施V2的建议的方式?

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?

推荐答案

如果您需要将自己的形象在地球的表面上,使用GroundOverlay。该方法 addGroundOverlay 增加了这样的图像。它采用 GroundOverlayOptions 的,允许指定图像的大小和位置(在纬度长而言),并且还 BitmapDesc​​riptor ,除其他选项,可以使用普通的位图作为图像源。所以,你可以创建一个新的位图,创建帆布解决此位图和油漆那里。

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.

似乎是一个很好的方法,如果你需要画的东西非常复杂,一些对于多边形和标记是不够的。此外,老code绘制在画布上大概可以重复使用。

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.

在上面把额外的组件可能是有问题的,因为它必须支持缩放,移动和地图,现在甚至3D。

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