マーカーがクリックされると、カメラのデフォルトの動作は画面の中央に表示されますが、通常は情報ウィンドウに長いテキストの説明があるため、実際にカメラの位置を変更してマーカーが画面の下部にくるようにする方が便利です。画面(画面中央に情報ウィンドウを作成)。以下のようにonMarkerClick関数をオーバーライドすることでそれができるはずだと思います(この関数がtrueを返すと、デフォルトの動作はキャンセルされます)
@Override
public boolean onMarkerClick(final Marker marker) {
// Google sample code comment : We return false to indicate that we have not
// consumed the event and that we wish
// for the default behavior to occur (which is for the camera to move
// such that the
// marker is centered and for the marker's info window to open, if it
// has one).
marker.showInfoWindow();
CameraUpdate center=
CameraUpdateFactory.newLatLng(new LatLng(XXXX,
XXXX));
mMap.moveCamera(center);//my question is how to get this center
// return false;
return true;
}
編集:
受け入れられた回答の手順、以下のコードを使用して解決された問題:
@Override
public boolean onMarkerClick(final Marker marker) {
//get the map container height
LinearLayout mapContainer = (LinearLayout) findViewById(R.id.map_container);
container_height = mapContainer.getHeight();
Projection projection = mMap.getProjection();
LatLng markerLatLng = new LatLng(marker.getPosition().latitude,
marker.getPosition().longitude);
Point markerScreenPosition = projection.toScreenLocation(markerLatLng);
Point pointHalfScreenAbove = new Point(markerScreenPosition.x,
markerScreenPosition.y - (container_height / 2));
LatLng aboveMarkerLatLng = projection
.fromScreenLocation(pointHalfScreenAbove);
marker.showInfoWindow();
CameraUpdate center = CameraUpdateFactory.newLatLng(aboveMarkerLatLng);
mMap.moveCamera(center);
return true;
}
助けてくれてありがとう^ ^