[英]How to adjust zoom level to fit boundary and then center map in marker offset?
我有一個谷歌地圖(com.google.android.gms.maps.GoogleMap),我有一些標記設置。
我能夠,分開,
1)調整縮放級別並將地圖置於邊界中心:
mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(getZoomBounds(), 10));
和
2)將地圖置於其中一個標記上方:
LatLng poiSelectedLatLng = new LatLng(markerSelected.getPosition().latitude
+ offset, markerSelected.getPosition().longitude);
mMap.animateCamera(CameraUpdateFactory.newLatLng(poiSelectedLatLng));
但是,對於我的生活,我不能同時做兩件事,使用newLatLngBounds調整縮放級別,然后將地圖置於其他地方。 無論我做什么,都是我在地圖上看到的。
我該怎么做呢?
對於未來的訪客,您可以使用相機動畫鏈接:
map.animateCamera(CameraUpdateFactory.newLatLngBounds(getZoomBounds(), 10), 2000, new CancelableCallback() {
@Override
public void onFinish() {
LatLng poiSelectedLatLng = new LatLng(markerSelected.getPosition().latitude + offset, markerSelected.getPosition().longitude);
map.animateCamera(CameraUpdateFactory.newLatLng(poiSelectedLatLng));
}
@Override
public void onCancel() {
}
});
另請參閱AnimateCameraChainingExampleActivity.java以獲取無限鏈接的示例。
嘗試同時使用moveCamera
和animateCamera
......
mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(getZoomBounds(), 10));
LatLng poiSelectedLatLng = new LatLng(markerSelected.getPosition().latitude
+ offset, markerSelected.getPosition().longitude);
mMap.animateCamera(CameraUpdateFactory.newLatLng(poiSelectedLatLng));
moveCamera
將直接移動到那個位置,而animateCamera
將提供移動效果。 它們本質上是線性的,所以一個將在另一個之后發生,但是如上所述將它們分層將提供您正在尋找的潛在效果 。
如果您試圖在UI上查看兩個調用的實際移動,則需要在完成動畫時根據需要注冊回調。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.