我正在使用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;
}
}
}