我的应用程序中有2个ItemizedOverlay
实例,一个是CurrentLocation
实例,另一个是其他实例。我已将这2个叠加层添加到MapView
。
倾斜地图的刷新按钮时,我想更新CurrentLocation
叠加层。如果我这样做了,则意味着它也显示了先前的当前位置,也显示了新的位置。如何删除上一个?
但是我还需要显示另一个覆盖图。
我将ItemizedOverlay
细分为:
MyItemizedOverlay currentOverlay = new MyItemizedOverlay(pushPinDrawable);
MyItemizedOverlay anotherOverlay = new MyItemizedOverlay(drawable);
刷新按钮的代码:
if (currentGeo != null) {
mapView.getOverlays().remove(currentOverlay);
mapVite();
mapOverlays = mapView.getOverlays();
myLocationOverlay = new OverlayItem(currentGeo, "My Location", mapTime.format(new Date(myLocationTime)));
// (currentGeo is the updated current geo point.)
currentOverlay.addOverlay(myLocationOverlay);
mapOverlays.add(currentOverlay);
mapController.animateTo(currentGeo);
} else {
Toast.makeText(this, "Your Current Location is temporarily unavailable", Toast.LENGTH_LONG).show();
}
任何想法?
最佳答案
你应该有这样的东西
public void onLocationChanged(Location location) {
if (mMyOverlay == null) {
mMyOverlay = new myOverlay(getResources().getDrawable(R.drawable.arrow), MyMap);
MyMap.getOverlays().add(mMyOverlay);
} else {
MyMap.getOverlays().remove(mMyOverlay);
MyMap.invalidate();
mMyOverlay = new myOverlay(getResources().getDrawable(R.drawable.arrow), MyMap);
MyMap.getOverlays().add(mMyOverlay);
}
if (location != null) {
MyMap.invalidate();
GeoPoint MyPos = new GeoPoint(microdegrees(location.getLatitude()), microdegrees(location.getLongitude()));
MyController.animateTo(MyPos);
mMyOverlay.addPoint(MyPos, "My position", "My position");
}