在我的代码中,我在地图上有两个活动第一个活动节目制作者,第二个活动显示有关该标记的信息。在异步任务中,我正在搜索某个位置并将信息对象添加为制造商的标签。就像我们一样
maker.setTag(obj);
当我点击标记onMarkerclick()被调用时,我通过在标记上调用getTag()获得obj,第二个活动开始并显示详细信息
直到这里一切正常。但是当我按下后退按钮并再次单击该标记时,它会从marker.getTag()返回null。下面是我的onMarkerClick方法
@Override
public boolean onMarkerClick(Marker marker) {
if (marker.getTag().toString().equals("JobSeeker")) {
// this is user current location show i dont want to do anything when marker is clicked
return false;
}
if (previousMarker != null && previousMarker.equals(marker)) {
//this code is executed if marker is clicked second time
LinkedTreeMap jobPost = (LinkedTreeMap) marker.getTag();
marker.setTag(jobPost);
Intent intent = new Intent(this, JobSearchResultActivity.class);
intent.putExtra("JobPost", jobPost);
Toast.makeText(this, "jobPostdetails" , Toast.LENGTH_SHORT).show();
startActivity(intent);
} else {
// just showing some toast that marker is selected
previousMarker = marker;
Toast.makeText(this, "selected" , Toast.LENGTH_SHORT).show();
marker.showInfoWindow();
}
return false;
}
请帮帮我。我不知道我在哪里或者可能是一个愚蠢的错误
答案 0 :(得分:0)
我认为你必须重新加载标记数据。例如
map.clear();
...
List<CustomModel> models = getModels();
foreach( CustomModels m : models ){
Marker marker = googleMap.addMarker(
new MarkerOptions()
.position(m.getLocation())
.icon(BitmapDescriptorFactory.fromResource(R.drawable.img_userpin)));
marker.setTag(m);
}