如何在谷歌地图集群实用程序Android中设置信息窗口详细信息?
我正试图在Android系统的谷歌地图上显示一个场馆列表,可以在缩小和放大时进行集群,而不进行集群 取消聚集后,可以打开单个项目信息窗口以查看该场馆的详细信息,然后单击以打开单独的活动 我在用这个 我正在这样做: 正在onResume()中获取映射片段 MapReadyCallback:如何在谷歌地图集群实用程序Android中设置信息窗口详细信息?,android,google-maps,android-fragments,Android,Google Maps,Android Fragments,我正试图在Android系统的谷歌地图上显示一个场馆列表,可以在缩小和放大时进行集群,而不进行集群 取消聚集后,可以打开单个项目信息窗口以查看该场馆的详细信息,然后单击以打开单独的活动 我在用这个 我正在这样做: 正在onResume()中获取映射片段 MapReadyCallback: private class VenuesInLocationOnMapReadyCallback implements OnMapReadyCallback { private static final
private class VenuesInLocationOnMapReadyCallback implements OnMapReadyCallback {
private static final float ZOOM_LEVEL = 10;
private final Context context;
public VenuesInLocationOnMapReadyCallback(Context context) {
this.context = context;
}
@Override
public void onMapReady(final GoogleMap map) {
// Setting up marker clusters
setUpClusterManager(getContext(), map);
// Allowing user to select My Location
map.setMyLocationEnabled(true);
// My location button handler to check the location setting enable
map.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener() {
@Override
public boolean onMyLocationButtonClick() {
promptForLocationSetting(getContext(), map);
// Returning false ensures camera try to move to user location
return false;
}
});
map.getUiSettings().setMyLocationButtonEnabled(true);
// Disabling map toolbar
map.getUiSettings().setMapToolbarEnabled(false);
}
}
设置群集管理器
private void setUpClusterManager(final Context context, GoogleMap map) {
// Declare a variable for the cluster manager.
ClusterManager<LocationMarker> mClusterManager;
// Position the map.
LatLng wocLatLng = new LatLng(28.467948, 77.080685);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(wocLatLng, VenuesInLocationOnMapReadyCallback.ZOOM_LEVEL));
// Initialize the manager with the context and the map.
mClusterManager = new ClusterManager<LocationMarker>(context, map);
// Point the map's listeners at the listeners implemented by the cluster
// manager.
map.setOnCameraChangeListener(mClusterManager);
map.setOnMarkerClickListener(mClusterManager);
// Add cluster items (markers) to the cluster manager.
addLocations(mClusterManager);
// Setting custom cluster marker manager for info window adapter
map.setInfoWindowAdapter(mClusterManager.getMarkerManager());
mClusterManager.getMarkerCollection().setOnInfoWindowAdapter(new MyLocationInfoWindowAdapter());
map.setOnInfoWindowClickListener(new MyMarkerInfoWindowClickListener());
}
MarkerInfoWindowClickListener
private class MyMarkerInfoWindowClickListener implements GoogleMap.OnInfoWindowClickListener {
@Override
public void onInfoWindowClick(Marker marker) {
// TODO: This is the click listener, that means all the info must be added as Tag to Marker
Intent venueDetailsDisplayIntent = new Intent(getActivity(), VenueDetailsDisplayActivity.class);
startActivity(venueDetailsDisplayIntent);
}
}
位置标记类
public class LocationMarker implements ClusterItem{
private final LatLng mPosition;
private final int id;
public LocationMarker(double lat, double lng, int id) {
mPosition = new LatLng(lat, lng);
this.id = id;
}
@Override
public LatLng getPosition() {
return mPosition;
}
public int getId() {
return this.id;
}
}
我理解流程的方式是:
onResume-->fragmentTransaction-->VenueSLocationOnMapReadyCallback-->setUpClusterManager-->添加位置(这将添加自定义标记)
标记单击-->MyLocationInfoWindowAdapter-->获取信息内容(标记)
标记信息窗口单击-->MyMarkerInfoWindowClickListener
private class MyMarkerInfoWindowClickListener implements GoogleMap.OnInfoWindowClickListener {
@Override
public void onInfoWindowClick(Marker marker) {
// TODO: This is the click listener, that means all the info must be added as Tag to Marker
Intent venueDetailsDisplayIntent = new Intent(getActivity(), VenueDetailsDisplayActivity.class);
startActivity(venueDetailsDisplayIntent);
}
}
根据我对过程的理解(我可能错了):
在addLocations功能中添加标记时,我正在向自定义LocationMarker添加id
我需要在信息窗口中为不同的标记显示不同的信息
使用MyLocationInfoWindowAdapter-->getInfoContents(标记)显示信息窗口
但问题是,我找不到一种方法来确定点击了哪个标记,以便在InfoWindow中设置适当的信息
单击打开的信息窗口,我需要打开一个单独的活动。A/C对我的信息窗口单击是使用MyMarkerInfoWindowClickListener-->onInfoWindowClick(标记器)处理的。在这里,我也遇到了同样的问题(我无法确定单击了哪个标记器的信息窗口)。第一个问题的可能重复,请参阅链接答案中的
clickedClusterItem
。对于第二个问题,使用实现ClusterManager,而不是实现GoogleMap。OnInfoWindowClickListener
使用实现ClusterManager。OnClusterInFoWindowClickListener
,然后实现OnClusterInFoWindowClick()
方法。有关更多详细信息,请参阅链接问题中的答案。对于第一个问题,请参阅链接答案中的Clicked ClusterItem
。对于第二个问题,使用实现ClusterManager,而不是实现GoogleMap。OnInfoWindowClickListener
使用实现ClusterManager。OnClusterInFoWindowClickListener
,然后实现OnClusterInFoWindowClick()
方法。有关更多详细信息,请参阅链接问题中的答案。
private class MyMarkerInfoWindowClickListener implements GoogleMap.OnInfoWindowClickListener {
@Override
public void onInfoWindowClick(Marker marker) {
// TODO: This is the click listener, that means all the info must be added as Tag to Marker
Intent venueDetailsDisplayIntent = new Intent(getActivity(), VenueDetailsDisplayActivity.class);
startActivity(venueDetailsDisplayIntent);
}
}
public class LocationMarker implements ClusterItem{
private final LatLng mPosition;
private final int id;
public LocationMarker(double lat, double lng, int id) {
mPosition = new LatLng(lat, lng);
this.id = id;
}
@Override
public LatLng getPosition() {
return mPosition;
}
public int getId() {
return this.id;
}