나는이 내가 시도 할 것입니다 MarkerCluster
사용자 정보
를 사용하여 각 마커에 대해 서로 다른 값으로 사용자 정보창을 렌더링하기 위해 노력하고 있어요 :
private final GoogleMap.InfoWindowAdapter mInfoWindowAdapter = new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {
View window = null;
if(getActivity()!=null&&isAdded()){
window = getActivity().getLayoutInflater().inflate(R.layout.map_objective_overlay, null);
final CustomFontTextView nameTV = (CustomFontTextView) window.findViewById(R.id.nameTV);
if(clickedClusterItem!=null){
System.out.println("You clicked this: "+clickedClusterItem.getName());
}else{
System.out.println("The clicked cluster item was nulllll");
}
if (clickedCluster != null) {
for (Objective item : clickedCluster.getItems()) {
// Extract data from each item in the cluster as needed
if(item.getRemoteId().equals(clickedClusterItem.getRemoteId())){
nameTV.setText(clickedClusterItem.getName());
}
}
}
}
return window;
}
@Override
public View getInfoContents(Marker marker) {
return null;
}
};
private Objective clickedClusterItem;
private Cluster<Objective> clickedCluster;
@Override
public void onResume() {
super.onResume();
preferences = getActivity().getSharedPreferences(Constants.PREFS_NAME, Context.MODE_PRIVATE);
if (map == null) {
map = fragment.getMap();
mClusterManager = new ClusterManager<Objective>(getActivity(), map);
map.setOnCameraChangeListener(mClusterManager);
map.setOnMarkerClickListener(mClusterManager);
latitude = Double.parseDouble(preferences.getString(Constants.LATITUDE, "0"));
longitude = Double.parseDouble(preferences.getString(Constants.LONGITUDE, "0"));
map.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
.title("Hello " + preferences.getString(Constants.TOURIST_NAME, "tourist"))
.snippet("You are here")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_check_in)));
map.setInfoWindowAdapter(mClusterManager.getMarkerManager());
//mClusterManager.setRenderer(new ObjectiveClusterRenderer(getActivity(), map, mClusterManager));
mClusterManager.getClusterMarkerCollection().setOnInfoWindowAdapter(mInfoWindowAdapter);
mClusterManager.getMarkerCollection().setOnInfoWindowAdapter(mInfoWindowAdapter);
map.setOnMarkerClickListener(mClusterManager);
mClusterManager.setOnClusterClickListener(new ClusterManager.OnClusterClickListener<Objective>() {
@Override
public boolean onClusterClick(Cluster<Objective> cluster) {
clickedCluster = cluster; // remember for use later in the Adapter
return false;
}
});
mClusterManager.setOnClusterItemClickListener(new ClusterManager.OnClusterItemClickListener<Objective>() {
@Override
public boolean onClusterItemClick(Objective item) {
clickedClusterItem = item;
return false;
}
});
그리고 여기가 clustermanager에 마커를 추가 :
public void setUpClusterer(List<Objective> objectivesList) {
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 10));
addItems(objectivesList);
}
private void addItems(List<Objective> objectiveList) {
for (Objective anObjectiveList : objectiveList) {
Objective offsetItem = new Objective();
offsetItem.setRemoteId(anObjectiveList.getRemoteId());
offsetItem.setName(anObjectiveList.getName());
objectiveMap.put(offsetItem.getRemoteId(), offsetItem);
System.out.println("This is the remote ID: " + offsetItem.getRemoteId());
mClusterManager.addItem(offsetItem);
}
}
InfoWindow
의 레이아웃은 괜찮지 만, 내용은 null의 경우 clickedClusterItem
및 clickedCluster
은 항상 null입니다 ...
내가 잘못했을 수있는 것에 대한 힌트가 있습니까?
마커와 해당 개체가있는지도를 만드는 데 관련된 몇 가지 답변이 있지만 그 방법을 잘 모르겠습니다.
을 사용 했습니까? –
똑바로 내 build.gradle 파일에서 : 'compile'com.google.maps.android : android-maps-utils : 0.2 + '' –