我使用以下代碼在我添加標記後縮放到地圖上的最大縮放級別。它可以工作,但只有在500毫秒內可以運行。如果它拿出來,它不起作用。我知道我錯過了一些明顯的東西,但我不知道我錯過了什麼。任何人都可以告訴我,我需要將LatLngBounds代碼放在沒有Runnable的地方嗎?Google Maps Android LatLngBounds
// Expand our Zoom to fit all markers
LatLngBounds.Builder builder = new LatLngBounds.Builder();
//the include method will calculate the min and max bound.
builder.include(myLocationPin.getPosition());
builder.include(placeLocationPin.getPosition());
final LatLngBounds bounds = builder.build();
final int zoomWidth = getResources().getDisplayMetrics().widthPixels;
final int zoomHeight = getResources().getDisplayMetrics().heightPixels;
final int zoomPadding = (int) (zoomWidth * 0.10); // offset from edges of the map 12% of screen
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds,zoomWidth,zoomHeight,zoomPadding));
}
}, 500);