我正在使用 GoogleMaps 开发应用程序,但遇到了 ItemizedOverlay 的问题:覆盖显示正确,但只有在触摸屏幕时才会显示每个更改。我是 android 新手,所以我知道这可能不是叠加层的问题,而是 mapView 本身的问题,但我无法通过在网上搜索答案来解决这个问题。提前感谢!
有我的代码:(我在示例中看到的一切都是普通的)
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_location);
map = (MapView) findViewById(R.id.mapview);
map.setBuiltInZoomControls(true);
Drawable markerDefault = this.getResources().getDrawable(
R.drawable.star_icon);
markerDefault = resize(markerDefault, 50);
Drawable myselfIcon = this.getResources().getDrawable(
R.drawable.myself2);
myselfIcon = resize(myselfIcon, 50);
itemizedOverlay = new GroupLocationOverlay(markerDefault, myselfIcon,
this);
map.getOverlays().add(itemizedOverlay);
}
private class GroupLocationOverlay extends ItemizedOverlay<OverlayItem> {
Drawable myIcon;
private int numOfMembers = 0;
HashMap<String, Integer> nameTable = new HashMap<String, Integer>();
HashMap<Integer, OverlayItem> overlays = new HashMap<Integer, OverlayItem>();
public GroupLocationOverlay(Drawable icon, Drawable self,
Context context) {
super(boundCenterBottom(icon));
ctxt = context;
myIcon = self;
populate();
}
public void clear() {
nameTable.clear();
overlays.clear();
numOfMembers = 0;
setLastFocusedIndex(-1);
populate();
}
public void addItem(double lat, double lng, String id, String time) {
GeoPoint point = new GeoPoint((int) (1E6 * lat), (int) (1E6 * lng));
OverlayItem item = new OverlayItem(point, id, time);
if (id.equals(identity)) {
item.setMarker(boundCenterBottom(myIcon));
}
Integer index = nameTable.get(id);
if (index == null) {// new member
index = Integer.valueOf(numOfMembers++);
nameTable.put(id, index);
}
overlays.put(index, item);
setLastFocusedIndex(-1);
populate();
}
@Override
protected OverlayItem createItem(int index) {
Integer i = Integer.valueOf(index);
return overlays.get(i);
}
@Override
public int size() {
return numOfMembers;
}
}
}