我有一张 map ,其中显示了由折线连接的一系列点,该 map 是 LiteMode,但在某些情况下,当使用这些点创建 LatLngBounds 并更新相机时,一些点会被遗漏在 map 之外。
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (LatLng latLng : listPoints) {
builder.include(latLng);
}
LatLngBounds bounds = builder.build();
int padding = 0; //offset from edges of the map in pixels
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
map.moveCamera(cu);
我该如何解决?
通过折线,我们可以看到即使更改填充,它们也看不见: 所以如果我删除 LiteMode 就会看到:
最佳答案
我解决了这个问题!
根据谷歌地图精简模式 documentation说:
Camera position, zoom, and animation
Supported? Partly
You can set the camera target and zoom, but not the tilt or bearing. Zoom level is rounded to the nearest integer in lite mode. Calling GoogleMap.moveCamera() will give you another static map image. For more information on setting and manipulating the camera, see Changing the View.
我的解决方案是从 map 中获取可见区域并进行比较,看看我的列表中是否有任何点在该区域之外,如果是,我应用 ZoomOut 来充分缩小相机,以便我的所有点都在可见区域。
for (LatLng latLng : listPoints) {
if (!(map.getProjection().getVisibleRegion().latLngBounds.contains(latLng))) {
map.moveCamera(CameraUpdateFactory.zoomOut());
break;
}
}
据我了解,显然问题在于,如果缩放级别为 7.4,则通过四舍五入到最接近的整数来正确显示 map 上的所有点:7,与 LiteMode This disabled 舍入为 8 时相比,宝贵的 .4 利润损失了。
我不知道这是否是最佳选择,但问题已解决。欢迎任何意见! :)
关于android - LatLngBounds 或 CameraUpdate 不显示 Maps Lite 模式中的所有点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41317561/