I working with maps and in my app I have a SupportMapFragment filling whole screen. When a marker is clicked a popup shows. This popup when shown get 75% of the screen.
Because of that I need to center the marker in the remaining 25%. To do that I'm using setOnClusterItemClickListener from CluserManager. But no matter what I do the marker always goes to the center of the SupportMapFragment.
I tried most solutions from this answer:
How to center the camera so that marker is at the bottom of screen? (Google map api V2 Android)
No success. Below I put some code. What I would like to know is why marker continues to go to center of the screen.
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);
}
});