Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
删除谷歌地图(Android 2.2)中的所有MapOverlays_Android_Google Maps - Fatal编程技术网

删除谷歌地图(Android 2.2)中的所有MapOverlays

删除谷歌地图(Android 2.2)中的所有MapOverlays,android,google-maps,Android,Google Maps,我想删除以前创建的所有MapOverlays。 不幸的是,我的代码不起作用。 谢谢 编辑: 现在我用mapView.postInvalidate()更正了它; 同样的问题也发生了。 这是我的全部代码: public class GMapsSubActivity extends MapActivity { Button b1; TextView t1, t2; MapView mapView; Drawable marker; GMapsItemizedOverlay itemizedoverl

我想删除以前创建的所有MapOverlays。 不幸的是,我的代码不起作用。 谢谢

编辑: 现在我用mapView.postInvalidate()更正了它; 同样的问题也发生了。 这是我的全部代码:

public class GMapsSubActivity extends MapActivity {

Button b1;
TextView t1, t2;
MapView mapView;
Drawable marker;
GMapsItemizedOverlay itemizedoverlay, markerOverlay;
List<Overlay> mapOverlays;
MapController mc;
int i;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_gmaps_sub);

    mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);

    GeoPoint htl = new GeoPoint(47821995, 13046345);

    mc = mapView.getController();
    mc.setCenter(htl);
    mc.setZoom(17);

    marker = this.getResources().getDrawable(R.drawable.marker);
    markerOverlay = new GMapsItemizedOverlay(marker, this);

    this.b1 = (Button) findViewById(R.id.gmapssub_button1);
    this.t1 = (TextView) findViewById(R.id.gmapssub_textView1);
    this.t2 = (TextView) findViewById(R.id.gmapssub_textView2);

    // onClickListener zuweisen
    this.b1.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            toggleSatellite();
        }
    });

    i = 8;

    // LocationManager
    LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    LocationListener ll = new LocationListener() {

        public void onStatusChanged(String provider, int status, Bundle extras) {
            // TODO Auto-generated method stub

        }

        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub

        }

        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub

        }

        public void onLocationChanged(Location location) {
            // TODO Auto-generated method stub
            if (location != null) {
                double pLat = location.getLatitude();
                double pLong = location.getLongitude();

                t1.setText(Double.toString(pLat));
                t2.setText(Double.toString(pLong));

                if(i == 8) {
                    i = 0;
                    mapOverlays = mapView.getOverlays();
                    mapOverlays.clear();

                    GeoPoint myPos = new GeoPoint((int) (pLat * 1E6), (int) (pLong * 1E6));
                    OverlayItem overlayitem = new OverlayItem(myPos, "Your current Location", "You are here!");
                    markerOverlay.addOverlay(overlayitem);
                    mapOverlays.add(markerOverlay);

                    mapView.postInvalidate();

                    mc.animateTo(myPos);
                } else {
                    i++;
                }
            }
        }
    };

    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_gmaps_sub, menu);
    return true;
}

@Override
protected boolean isRouteDisplayed() {
    return false;
}

private void toggleSatellite() {
    if (mapView.isSatellite() == true) {
        mapView.setSatellite(false);
    } else {
        mapView.setSatellite(true);
    }
}
}
public类gmapsubactivity扩展了mappactivity{
按钮b1;
文本视图t1、t2;
地图视图;
可拉拔标记;
GMapsItemizedOverlay itemizedoverlay、markerOverlay;
列出地图覆盖图;
地图控制器;
int i;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u gmaps\u sub);
mapView=(mapView)findViewById(R.id.mapView);
mapView.SetBuilTinZoomControl(真);
地质点htl=新的地质点(47821995,13046345);
mc=mapView.getController();
mc.setCenter(htl);
mc.setZoom(17);
marker=this.getResources().getDrawable(R.drawable.marker);
markerOverlay=新的GMapsItemizedOverlay(marker,this);
this.b1=(按钮)findViewById(R.id.gmapsub_按钮1);
this.t1=(TextView)findViewById(R.id.gmapsub_textView1);
this.t2=(TextView)findViewById(R.id.gmapsub_textView2);
//祖维森酒店
this.b1.setOnClickListener(新的OnClickListener(){
公共void onClick(视图v){
//TODO自动生成的方法存根
切换卫星();
}
});
i=8;
//位置经理
LocationManager lm=(LocationManager)getSystemService(Context.LOCATION\u服务);
LocationListener ll=新LocationListener(){
public void onStatusChanged(字符串提供程序、int状态、Bundle extra){
//TODO自动生成的方法存根
}
公共无效onProviderEnabled(字符串提供程序){
//TODO自动生成的方法存根
}
公共无效onProviderDisabled(字符串提供程序){
//TODO自动生成的方法存根
}
已更改位置上的公共无效(位置){
//TODO自动生成的方法存根
如果(位置!=null){
双平台=location.getLatitude();
double-pLong=location.getLongitude();
t1.setText(双toString(pLat));
t2.setText(Double.toString(pLong));
如果(i==8){
i=0;
mapOverlays=mapView.getOverlays();
mapOverlays.clear();
地质点myPos=新的地质点((内部)(平台*1E6),(内部)(平台*1E6));
OverlayItem OverlayItem=新的OverlayItem(myPos,“您当前的位置”,“您在这里!”);
markerOverlay.addOverlay(overlayitem);
mapOverlays.add(markerOverlay);
mapView.postInvalidate();
动画师(myPos),;
}否则{
i++;
}
}
}
};
lm.RequestLocationUpdate(LocationManager.GPS_提供程序,0,0,ll);
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
getMenuInflater().充气(R.menu.activity\u gmaps\u子菜单);
返回true;
}
@凌驾
受保护的布尔值isRouteDisplayed(){
返回false;
}
私有void toggleSatellite(){
if(mapView.isSatellite()==true){
mapView.setSatellite(假);
}否则{
mapView.setSatellite(真);
}
}
}

尝试
mapView.postInvalidate()
而不是
mapView.invalidate()
。请参阅>地图视图>getOverlays()。

您试图实现的目标是什么?
public class GMapsSubActivity extends MapActivity {

Button b1;
TextView t1, t2;
MapView mapView;
Drawable marker;
GMapsItemizedOverlay itemizedoverlay, markerOverlay;
List<Overlay> mapOverlays;
MapController mc;
int i;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_gmaps_sub);

    mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);

    GeoPoint htl = new GeoPoint(47821995, 13046345);

    mc = mapView.getController();
    mc.setCenter(htl);
    mc.setZoom(17);

    marker = this.getResources().getDrawable(R.drawable.marker);
    markerOverlay = new GMapsItemizedOverlay(marker, this);

    this.b1 = (Button) findViewById(R.id.gmapssub_button1);
    this.t1 = (TextView) findViewById(R.id.gmapssub_textView1);
    this.t2 = (TextView) findViewById(R.id.gmapssub_textView2);

    // onClickListener zuweisen
    this.b1.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            toggleSatellite();
        }
    });

    i = 8;

    // LocationManager
    LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    LocationListener ll = new LocationListener() {

        public void onStatusChanged(String provider, int status, Bundle extras) {
            // TODO Auto-generated method stub

        }

        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub

        }

        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub

        }

        public void onLocationChanged(Location location) {
            // TODO Auto-generated method stub
            if (location != null) {
                double pLat = location.getLatitude();
                double pLong = location.getLongitude();

                t1.setText(Double.toString(pLat));
                t2.setText(Double.toString(pLong));

                if(i == 8) {
                    i = 0;
                    mapOverlays = mapView.getOverlays();
                    mapOverlays.clear();

                    GeoPoint myPos = new GeoPoint((int) (pLat * 1E6), (int) (pLong * 1E6));
                    OverlayItem overlayitem = new OverlayItem(myPos, "Your current Location", "You are here!");
                    markerOverlay.addOverlay(overlayitem);
                    mapOverlays.add(markerOverlay);

                    mapView.postInvalidate();

                    mc.animateTo(myPos);
                } else {
                    i++;
                }
            }
        }
    };

    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_gmaps_sub, menu);
    return true;
}

@Override
protected boolean isRouteDisplayed() {
    return false;
}

private void toggleSatellite() {
    if (mapView.isSatellite() == true) {
        mapView.setSatellite(false);
    } else {
        mapView.setSatellite(true);
    }
}
}