0
我有小問題羣集和自定義InfoWindow。如何顯示infowindow沒有羣集點擊
我不想在單擊羣集時顯示Infowindow。 但我的應用程序顯示Infowindow,當我點擊clusterItem並單擊Cluter。它顯示最後點擊ClusterItem的Infowindow。
代碼:
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));
}
}
評論這個'mMap.setOnM arkerClickListener(mClusterManager);'然後嘗試 –
@Rajesh Kushvaha謝謝commnet我的問題。我會試試這個。但結果是一樣的。 – Jin