I might edit this answer later to provide some code, but what I think could work is this:
- Get
LatLng
(LatLng M) of the clicked marker. - Convert LatLng M to a
Point
(Point M) using theProjection.toScreenLocation(LatLng)
method. This gives you the location of the marker on the device’s display (in pixels). - Compute the location of a point (New Point) that’s above Point M by half of the map’s height.
- Convert the New Point back to
LatLng
and center the map on it.
Look here for my answer on how to get the map’s height.
// googleMap is a GoogleMap object
// view is a View object containing the inflated map
// marker is a Marker object
Projection projection = googleMap.getProjection();
LatLng markerPosition = marker.getPosition();
Point markerPoint = projection.toScreenLocation(markerPosition);
Point targetPoint = new Point(markerPoint.x, markerPoint.y - view.getHeight() / 2);
LatLng targetPosition = projection.fromScreenLocation(targetPoint);
googleMap.animateCamera(CameraUpdateFactory.newLatLng(targetPosition), 1000, null);