0
J'ai un petit problème de Cluster et Personnalisé InfoWindow.Comment afficher infowindow sans cluster cliquez sur
Je ne souhaite pas afficher Infowindow lorsque je clique sur un cluster. Mais mon application est show Infowindow lorsque je clique sur clusterItem et clique sur Cluter. Il montre le dernier clic sur Infowindow de ClusterItem.
code:
public class MapsLActivity extends FragmentActivity implements OnMapReadyCallback, ClusterManager.OnClusterItemClickListener<House>, GoogleMap.OnMapClickListener, ClusterManager.OnClusterClickListener<House>{
private GoogleMap mMap;
private View infoWindow;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps_k);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.getUiSettings().setZoomControlsEnabled(true);
ClusterManager<House> mClusterManager = new ClusterManager<>(this, mMap);
mMap.setOnMapClickListener(this);
mMap.setOnMarkerClickListener(mClusterManager);
mMap.setOnCameraChangeListener(mClusterManager);
AssetManager assetManager = getResources().getAssets();
try {
AssetManager.AssetInputStream ais = (AssetManager.AssetInputStream) assetManager.open("yb_edu.json");
BufferedReader br = new BufferedReader(new InputStreamReader(ais));
StringBuilder sb = new StringBuilder();
int bufferSize = 1024 * 1024;
char readBuf[] = new char[bufferSize];
int resultSize = 0;
while ((resultSize = br.read(readBuf)) != -1) {
if (resultSize == bufferSize) {
sb.append(readBuf);
} else {
for (int i = 0; i < resultSize; i++) {
sb.append(readBuf[i]);
}
}
}
String jString = sb.toString();
JSONObject object = new JSONObject(jString);
JSONArray list = new JSONArray(object.getString("yb_edu"));
for (int i = 0; i < list.length(); i++) {
JSONObject inside = list.getJSONObject(i);
String title = inside.getString("title");
String lats = inside.getString("lat");
String lngs = inside.getString("lng");
double lat = Double.parseDouble(lats);
double lng = Double.parseDouble(lngs);
LatLng position = new LatLng(lat, lng);
Log.v("@@@", "postion : " + position);
Log.v("@@[email protected]@", String.valueOf(i));
i++;
mClusterManager.addItem(new House(position, title));
}
mClusterManager.cluster(); //클러스터 새로고침
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
mClusterManager.setOnClusterItemClickListener(this);
mClusterManager.setOnClusterClickListener(this);
}
@Override
public boolean onClusterItemClick(final House house) {
Toast.makeText(this, "onClusterItemClick", Toast.LENGTH_SHORT).show();
LatLng latLng = house.getLatLng();
Log.v("@@", "LatLng : " + latLng);
infoWindow = getLayoutInflater().inflate(R.layout.markerinfo, null);
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {
((TextView)infoWindow.findViewById(R.id.tx_infoWindowTitle)).setText(house.getTitle());
((TextView)infoWindow.findViewById(R.id.tx_infoWindowContent)).setText(house.getLatLng().toString());
return infoWindow;
}
@Override
public View getInfoContents(Marker marker) {
return null;
}
});
return false;
}
@Override
public boolean onClusterClick(Cluster<House> cluster) {
mMap.moveCamera(CameraUpdateFactory.zoomIn());
Toast.makeText(this, "onClusterClick", Toast.LENGTH_SHORT).show();
return false;
}
@Override
public void onMapClick(LatLng latLng) {
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
}
}
commentez ce 'mMap.setOnM arkerClickListener (mClusterManager); 'alors essayez –
@Rajesh Kushvaha Merci pour commnet ma question. Je vais essayer ça. mais le résultat est le même. – Jin