java - JAVA Google Maps API:根据缩放值设置边界
问题描述
每次缩放值更改时,我都会尝试更新相机边界。检查文档后,我发现可以通过使用LatLngBounds Including(LatLng point)
返回包含 LatLng 点的最小 LatLngBounds 的方法来扩展当前边界。所以我做了这个代码:
// I save the initial zoom value and I test if it changes
double zoom = mMap.getCameraPosition().zoom;
if (zoom!= mMap.getCameraPosition().zoom){
// I create a new Bounds which is proportional to the difference of the previous and the new zoom value by including a new point in the boundaries
LatLng chgtBounds = new LatLng(ParisBounds.getCenter().latitude+(mMap.getCameraPosition().zoom-zoom)*0.001,ParisBounds.getCenter().longitude+(mMap.getCameraPosition().zoom-zoom)*0.001);
zoom = mMap.getCameraPosition().zoom;
// I apply this new bounds on the map and it automatically delete the previous one
mMap.setLatLngBoundsForCameraTarget(ParisBounds.including(chgtBounds));
}
我创建了一个新变量来保存缩放值,以了解用户何时放大地图。当他这样做时,通过将前一个边界增加缩放值的千分之一来创建一个新的边界(不确定这是正确的分数,但想法是相同的)。但是,我认为这些行只在应用程序启动时执行一次。有没有办法永远执行它们?我试过了while(true)
,但应用程序根本没有启动。
解决方案
推荐阅读
- javascript - 如何在浏览器中显示 json 值?
- typescript - Typescript 基于条件类型的扩展行为不如预期
- javascript - 如何从我的 vue 路由器中的商店/状态访问此变量?
- java - Eclipse:找不到 javax.xml.datatype.XMLGregorianCalendar - Java 11
- r - 有没有一种有效的方法来读取 R 中的 .gz 文件?
- java - 如何使用加密密码连接到 PostgreSQL 服务器
- linux - 如何使用 bash 脚本从文本文件中选择特定范围的行
- android - 我在哪里报告 googles (firebase) 文档中的错误?[Firebase 设置指南]
- ios - 操作扩展 - 我如何知道主机应用程序何时支持修改?
- ruby-on-rails - 对于具有相同 URI 模式的路由,首先匹配哪个?