我使用地图工作,在我的应用程序中,我有一个supportmapfragment填充整个屏幕。单击标记时,弹出窗口显示。此弹出窗口显示为屏幕的75%。
因此,我需要将标记以剩余的25%为中心。为此,我正在使用CluserManager的SetOnClusterItemClicklistener。但是,无论我做什么,标记始终都会转到supportmapfragment的中心。
我尝试了此答案的大多数解决方案:
如何将相机中心置于屏幕底部?(Google Map API V2 Android)
没有成功。下面我放了一些代码。我想知道的是为什么Marker继续前往屏幕的中心。
clusterManager.setOnClusterItemClickListener(new ClusterManager.OnClusterItemClickListener<MyItem>() {
@Override
public boolean onClusterItemClick(MyItem myItem) {
LatLng location = myItem.getPosition();
/*float zoom_lvl = googleMap.getCameraPosition().zoom;
double dpPerdegree = 256.0*Math.pow(2, zoom_lvl)/170.0;
double screen_height = (double) mapFragment.getView().getHeight();
double screen_height_30p = 50.0*screen_height/100.0;
double degree_30p = screen_height_30p/dpPerdegree;
LatLng centerlatlng = new LatLng( location.latitude, location.longitude + degree_30p);
googleMap.animateCamera(CameraUpdateFactory.newLatLng(centerlatlng), 1000, null);*/
Projection projection = googleMap.getProjection();
LatLng markerPosition = myItem.getPosition();
Point markerPoint = projection.toScreenLocation(markerPosition);
Point targetPoint = new Point(markerPoint.x, markerPoint.y - mapFragment.getView().getHeight() / 4);
LatLng targetPosition = projection.fromScreenLocation(targetPoint);
googleMap.animateCamera(CameraUpdateFactory.newLatLng(targetPosition), 1000, null);
}
});
已解决。我只需要返回真实。返回false告诉clusterManager总是以屏幕上的标记为中心。