LatLngBounds 或 CameraUpdate 不显示 Maps Lite 模式中的所有点
LatLngBounds or CameraUpdate not show all points in Maps Lite Mode
我有一张地图,其中显示了由多段线链接的一系列点,该地图是 LiteMode,但在某些情况下,当使用这些点创建 LatLngBounds 并更新相机时,一些点被遗漏在地图之外。
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);
我该如何解决?
通过折线我们可以看到即使改变pading:也看不到它们
所以如果我删除 LiteMode 就会看到:
我解决了问题!
根据 Google Maps Lite 模式 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.
我的解决方案是从地图中获取可见区域并进行比较,看看我列表中的任何点是否在该区域之外,如果是,我应用 ZoomOut 将相机缩小到足够大,以便我所有的点都在在可见区域。
for (LatLng latLng : listPoints) {
if (!(map.getProjection().getVisibleRegion().latLngBounds.contains(latLng))) {
map.moveCamera(CameraUpdateFactory.zoomOut());
break;
}
}
据我了解,显然问题在于,如果缩放级别为 7.4,则通过四舍五入到最接近的整数来正确显示地图上的所有点:7,比 LiteMode This disabled 四舍五入到 8.
时损失了宝贵的 .4 余量
不知道是不是最优方案,但是问题已经解决了。欢迎任何意见! :)
我有一张地图,其中显示了由多段线链接的一系列点,该地图是 LiteMode,但在某些情况下,当使用这些点创建 LatLngBounds 并更新相机时,一些点被遗漏在地图之外。
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);
我该如何解决?
通过折线我们可以看到即使改变pading:
我解决了问题!
根据 Google Maps Lite 模式 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.
我的解决方案是从地图中获取可见区域并进行比较,看看我列表中的任何点是否在该区域之外,如果是,我应用 ZoomOut 将相机缩小到足够大,以便我所有的点都在在可见区域。
for (LatLng latLng : listPoints) {
if (!(map.getProjection().getVisibleRegion().latLngBounds.contains(latLng))) {
map.moveCamera(CameraUpdateFactory.zoomOut());
break;
}
}
据我了解,显然问题在于,如果缩放级别为 7.4,则通过四舍五入到最接近的整数来正确显示地图上的所有点:7,比 LiteMode This disabled 四舍五入到 8.
时损失了宝贵的 .4 余量不知道是不是最优方案,但是问题已经解决了。欢迎任何意见! :)