获取地图缩放级别的给定范围在Android像JS谷歌地图API:map.getBoundsZoomLevel(边界) [英] Getting map zoom level for given bounds on Android like on JS Google Maps API: map.getBoundsZoomLevel(bounds)

查看:815
本文介绍了获取地图缩放级别的给定范围在Android像JS谷歌地图API:map.getBoundsZoomLevel(边界)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个群集标记定义含有一组标记的矩形边框。群集具有一个中心(纬度,经度),标记物计​​数和一个经度和纬度跨度来计算边界

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.

在谷歌地图API(JS)有一个名为getBoundsZoomLevel(范围)功能,但我无法找到在谷歌地图SDK为Android等效方法。我如何估计的缩放级别定界(尤其是在不同分辨率/ densitys不同的设备)?

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.

有没有人工作code片断或一些建议好吗?

Has anybody a working code snippet or some suggestions for me?

在此先感谢 此致和Thorsten。

Thanks in advance Regards Thorsten.

推荐答案

感谢您的回答Solvek。同时我发现,我已经稍微适应的解决方案,它的工作原理。该方法计算一组地理点的范围,计算这些点的跨度,最后用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:

 public static void zoomInBounds(final MapView view, final GeoPoint.. bounds) {

    int minLat = Integer.MAX_VALUE;
    int minLong = Integer.MAX_VALUE;
    int maxLat = Integer.MIN_VALUE;
    int maxLong = Integer.MIN_VALUE;

    for (GeoPoint point : bounds) {
        minLat = Math.min(point.getLatitudeE6(), minLat);
        minLong = Math.min(point.getLongitudeE6(), minLong);
        maxLat = Math.max(point.getLatitudeE6(), maxLat);
        maxLong = Math.max(point.getLongitudeE6(), maxLong);
    }

    final MapController controller = view.getController();
    controller.zoomToSpan(
                       Math.abs(minLat - maxLat), Math.abs(minLong - maxLong));
    controller.animateTo(new GeoPoint((maxLat + minLat) / 2,
        (maxLong + minLong) / 2));
}

这篇关于获取地图缩放级别的给定范围在Android像JS谷歌地图API:map.getBoundsZoomLevel(边界)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆