在 Android 上获取给定边界的地图缩放级别,就像在 JS Google Maps API 上一样:map.getBoundsZoomLevel(bounds)
我有一个簇标记,它定义了包含一组标记的边界矩形。该簇具有中心(纬度、经度)、标记计数以及用于计算边界的纬度和经度跨度。
Google Maps API (JS) 有一个名为“getBoundsZoomLevel(bounds)”的函数,但我在 Android 版 Google Maps SDK 中找不到等效的方法。如何估计给定范围的缩放级别(尤其是在具有不同分辨率/密度的不同设备上)?
我计划用户可以触摸集群标记,地图视图将以该集群的中心和边界为中心。
有人给我提供工作代码片段或一些建议吗?
提前致谢 问候托尔斯滕。
I have a cluster marker that defines a bounding rectangle containing a group of markers. The cluster has a center (lat,lon), a marker count and a latitude and longitude span to calculate the bounds.
The Google Maps API (JS) has a function called "getBoundsZoomLevel(bounds)" but I cannot find an equivalent method in the Google Maps SDK for Android. How can I estimate the zoom level for given bounds (especially on different devices with different resolutions/densitys)?
I've planned that an user can touch a cluster marker and the map view will be centered to the center and the bounds of that cluster.
Has anybody a working code snippet or some suggestions for me?
Thanks in advance
Regards Thorsten.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
谢谢您的回答索尔维克。与此同时,我找到了一个稍微修改过的解决方案,并且它有效。该方法计算一组地理点的边界,计算这些点的跨度,最后使用 ZoomToSpan 和 animateTo 来放大给定区域并将其居中:
Thank you for your answer Solvek. Meanwhile I found a solution that I've adapted slightly and it works. The method computes the bounds of a set of geo points, computes the span of these points and finally uses zoomToSpan and animateTo for zooming into and centering the given area:
现在您可以使用 .newLatLngBounds() 方法缩放到边界:
它将移动并缩放到给定的边界,因此它们都在屏幕上可见(例如,城市或国家的不同缩放)。它与位置搜索完美配合。
Now you could zoom to bounds with .newLatLngBounds() method:
It will move and zoom to given bounds, so they all visible on a screen (e.g. different zoom for city or country). It works perfectly with location search.
我没有尝试过这个,但也许它对你有用。假设你有一个矩形 (x1,y1)-(x2,y2)
I didn't tried this but maybe it will work for you. Imagine you have a rectangle (x1,y1)-(x2,y2)