我正在使用mapbox sdk进行离线地图,我添加了像
这样的标记public void parseStops(String type) {
if (type.equals(activity.getResources().getString(R.string.allStops))) {
alStops = stopsOperations.selectData("walking");
} else {
Log.d("RouteType:", ":" + type);
alStops = stopsOperations.selectDataByType(type);
}
if (alStops.size() > 0) {
for (int i = 0; i < alStops.size(); i++) {
stopsEntity = new StopsEntity();
stopsEntity = alStops.get(i);
title = stopsEntity.getTitle();
lonngt = stopsEntity.getLongitude();
lat = stopsEntity.getLattitude();
routeType = stopsEntity.getType();
stopNumber = stopsEntity.getStopNumber();
Log.d("stopNumber:", ":" + stopNumber);
marker = new Marker(stopsEntity.getTitle(), "", new LatLng(
Double.parseDouble(stopsEntity.getLattitude()),
Double.parseDouble(stopsEntity.getLongitude())));
View view = ((LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.custom_marker_layout, null);
ivPin = (ImageView) view.findViewById(R.id.ivPin);
tvStopNumber = (TextView) view.findViewById(R.id.tvStopNumber);
if (routeType != null) {
if (routeType.equals(activity.getResources().getString(
R.string.walking1))
&& ((alStops.get(i).getStopNumber().equals("79"))
|| (alStops.get(i).getStopNumber()
.equals("98"))
|| (alStops.get(i).getStopNumber()
.equals("99")) || (alStops.get(i)
.getStopNumber().equals("125")))) {
ivPin.setImageResource(R.drawable.walking);
} else if (routeType.equals(activity.getResources()
.getString(R.string.red))) {
ivPin.setImageResource(R.drawable.pin_red);
} else if (routeType.equals(activity.getResources()
.getString(R.string.blue))) {
ivPin.setImageResource(R.drawable.blue_pin);
} else if (routeType.equals(activity.getResources()
.getString(R.string.orange))) {
ivPin.setImageResource(R.drawable.pin_orange);
} else if (routeType.equals(activity.getResources()
.getString(R.string.yellow))) {
ivPin.setImageResource(R.drawable.pin_yellow);
} else if (routeType.equals(activity.getResources()
.getString(R.string.lilac))) {
ivPin.setImageResource(R.drawable.pin_lilac);
} else if (routeType.equals(activity.getResources()
.getString(R.string.interchangee))) {
ivPin.setImageResource(R.drawable.pin_interchange);
}
}
if (stopNumber != null) {
if (stopNumber.length() < 2) {
tvStopNumber.setText("0" + stopNumber.toString());
} else {
tvStopNumber.setText(stopNumber.toString());
}
}
if (routeType != null
&& (alStops.get(i).getTitle().equalsIgnoreCase(activity
.getResources().getString(R.string.start)))
|| (alStops.get(i).getTitle().equalsIgnoreCase(activity
.getResources().getString(R.string.end)))) {
marker.setMarker(new BitmapDrawable(UDF
.createDrawableFromView1(activity, view)));
} else {
marker.setMarker(new BitmapDrawable(UDF
.createDrawableFromView1(activity, view)));
}
mv.addMarker(marker);
if (routeType != null
&& !routeType.equals(activity.getResources().getString(
R.string.walking1))) {
marker = new Marker(stopsEntity.getTitle(), "", new LatLng(
Double.parseDouble(stopsEntity.getLattitude()),
Double.parseDouble(stopsEntity.getLongitude())));
marker.setMarker(activity.getResources().getDrawable(
R.drawable.bus));
mv.addMarker(marker);
}
}
}
}
之后我需要删除这些所有添加的标记用于某些情况。 那么,我怎样才能同时删除所有标记。 谁能帮我?
答案 0 :(得分:1)
MapView
类有一个名为clear
的方法:
void clear()从地图的显示中删除所有标记。
https://www.mapbox.com/mapbox-android-sdk/api/0.7.0/com/mapbox/mapboxsdk/views/MapView.html#clear()
答案 1 :(得分:0)
对于mapbox-android-sdk:3.0.0,方法是:
mMapView.removeAllAnnotations();
并且,.clear()方法已不复存在。