我在MapView中添加了一些标记:
List<Overlay> mapOverlays;
Drawable drawable;
MapOverlay itemizedOverlay;
mapOverlays = mapView.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.map_dot_green);
itemizedOverlay = new MapOverlay(drawable, mapView);
GeoPoint markerPoint = new GeoPoint(lat, lng);
OverlayItem overlayItem = new OverlayItem(markerPoint, "name", "description");
itemizedOverlay.addOverlay(overlayItem);
mapOverlays.add(itemizedOverlay);
现在我需要定期更改标记(drawables
)。我计划使用Runnable
。但是我该如何更换标记?
UPD。这是相同的当前代码:
public class Map extends MapActivity {
private MapOverlay itemizedOverlay;
private MapView mapView;
private Runnable mUpdateMapMarkers = new Runnable() {
public void run() {
Drawable drawable_green = getResources().getDrawable(R.drawable.map_dot_green);
int w = drawable_green.getIntrinsicWidth();
int h = drawable_green.getIntrinsicHeight();
drawable_green.setBounds(-w / 2, -h, w / 2, 0);
for (int i = 0; i < itemizedOverlay.size(); i++) {
itemizedOverlay.getItem(i).setMarker(drawable_green);
}
mapView.invalidate();
mHandler.postDelayed(mUpdateMapMarkers, 5*60*1000); // once in 5 minutes
}
};
答案 0 :(得分:1)
使用LevelListDrawables
并更改级别,或创建自己的OverlayItem
子类并覆盖getMarker()
。 This sample project演示了后一种方法。