如何缩放MapView以便它总是包含两个地理点?

Oll*_*e C 4 android android-mapview

我有两个间歇性变化的地理点,并希望MapView调整大小并进行平移以确保两个点始终可见.我可以轻松地将地图重新​​定位在两者之间的中间位置,但是如何设置缩放级别以确保我的两个点可见?

Alo*_*lon 5

在另一篇文章中查看他的答案: Google Map V2如何设置ZoomToSpan?

它解决它没有太多的麻烦.请注意,您只能在地图加载至少一次后才能使用该功能.如果不在屏幕上使用具有指定地图大小的功能

LatLngBounds bounds = new LatLngBounds.Builder()
                    .include(new LatLng(CURRENTSTOP.latitude, CURRENTSTOP.longitude))
                    .include(new LatLng(MYPOSITION.latitude, MYPOSITION.longitude)).build();

Point displaySize = new Point();
getWindowManager().getDefaultDisplay().getSize(displaySize);

map.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, displaySize.x, 250, 30));
Run Code Online (Sandbox Code Playgroud)

像魅力和非常有活力的作品!