我正在尝试绘制从服务器获取的多个标记,然后在某些事件中删除它们,然后在按下取消按钮时将其绘制回来。每次我打电话
map.clear()
我收到此错误
java.lang.IllegalArgumentException: Released unknown imageData reference`
这是我从服务器获取详细信息后添加标记(通过调用plot_all_markers方法)的方法
try {
for (int i = 0; i < Constant.spot_details.size(); i++) {
LatLng latlng = new LatLng(Double.parseDouble(Constant.spot_details.get(i).geo_x),
Double.parseDouble(Constant.spot_details.get(i).geo_y));
final MarkerOptions marker = new MarkerOptions().position(latlng);
if (Constant.spot_details.get(i).type.equals("a")) {
marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.a_marker));
} else if (Constant.spot_details.get(i).type.equals("b")) {
marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.b_marker_grey));
} else
marker.icon(BitmapDescriptorFactory.fromBitmap(Utils.string_to_bitmap(Constant.spot_details.get(i).logo, activity)));
marker.title(Constant.spot_details.get(i).name);
final Marker m=mMap.addMarker(marker);
all_markers.add(m);
animate_marker_fade_in(m);
plotted_spot_array.add(Constant.spot_details.get(i));
marker_map.put(marker.getPosition().latitude + marker.getPosition().longitude, i);
}
} catch (Exception e) {
e.printStackTrace();
}
这是我如何从地图中删除标记并仅绘制一个需要的标记
mMap.clear();
PolylineOptions lineOptions = new PolylineOptions();
String s = "";
latLngs = new ArrayList<LatLng>();
try {
// s = result.getString("points");
s = Constant.request_spot.directions[0].overview_polyline.points;
latLngs = decodePoly(s);
s = "";
LatLng latLong = new LatLng(0, 0);
for (LatLng l : latLngs) {
lineOptions.add(l);
s = l.latitude + ", " + s;
latLong = l;
}
lineOptions.width(5);
lineOptions.color(R.color.theme_color);
_m = Demand.mMap.addMarker(new MarkerOptions().position(latLong)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.a_marker_yellow)));
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(new LatLng(Constant.request_spot.directions[0].legs[0].start_location.lat,
Constant.request_spot.directions[0].legs[0].start_location.lng));
builder.include(new LatLng(Constant.request_spot.directions[0].legs[0].end_location.lat,
Constant.request_spot.directions[0].legs[0].end_location.lng));
LatLngBounds bounds = builder.build();
int padding = 300; // offset from edges of the map in pixels
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
Demand.mMap.animateCamera(cu);
Demand.mMap.addPolyline(lineOptions);
cross_item.setVisible(true);
最后在按下cross_item时我再次调用mMap.clear(),但它在那行崩溃
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_filter) {
mMap.clear();
cross_item.setVisible(false);
plot_all_markers();
requestServer(mMap.getCameraPosition().target);
}
return super.onOptionsItemSelected(item);
}
这是我的Logcat输出
java.lang.IllegalArgumentException: Released unknown imageData reference
at maps.ce.i.a(Unknown Source)
at maps.ei.bh.c(Unknown Source)
at maps.ei.s.o(Unknown Source)
at maps.ei.bu.e(Unknown Source)
at com.google.android.gms.maps.internal.e$a.onTransact(:com.google.android.gms.alldynamite:205)
at android.os.Binder.transact(Binder.java:387)
at com.google.android.gms.maps.internal.IGoogleMapDelegate$zza$zza.clear(Unknown Source)
at com.google.android.gms.maps.GoogleMap.clear(Unknown Source)
at com.drishtigroup.needtopark.fragments.Demand.onOptionsItemSelected(Demand.java:499)
at android.support.v4.app.Fragment.performOptionsItemSelected(Fragment.java:2085)
at android.support.v4.app.FragmentManagerImpl.dispatchOptionsItemSelected(FragmentManager.java:2163)
at android.support.v4.app.FragmentController.dispatchOptionsItemSelected(FragmentController.java:304)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:410)
at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:167)
at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:100)
at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:100)
at android.support.v7.app.ToolbarActionBar$2.onMenuItemClick(ToolbarActionBar.java:69)
at android.support.v7.widget.Toolbar$1.onMenuItemClick(Toolbar.java:169)
at android.support.v7.widget.ActionMenuView$MenuBuilderCallback.onMenuItemSelected(ActionMenuView.java:760)
at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:811)
at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:958)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:948)
at android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:618)
at android.support.v7.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:139)
at android.view.View.performClick(View.java:5201)
at android.view.View$PerformClick.run(View.java:21163)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
如何避免此错误?
答案 0 :(得分:0)
IllegalArgumentException
意味着
异常,指示提供给方法或函数的参数对于其预期目的无效,或者与方法所期望的格式不同。
在这个github issue中,他们通过清除标记使用集群管理器来修复错误IllegalArgumentException:释放未知的imageData引用。这里建议不要直接从地图本身清除标记,而是使用集群管理器清除并添加标记。
mClusterManager.clearItems();
mClusterManager.addItems(mMapVenueItems);
mClusterManager.cluster();
我希望它可以帮助你解决问题。