Android地图V2 - 动画的相机,包括最标志 [英] Android Maps v2 - animate camera to include most markers

查看:105
本文介绍了Android地图V2 - 动画的相机,包括最标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组点从需要被显示在地图上一个Web服务来了。

I have a set of points coming from a webservice that need to be displayed on a map.

我有一个目前的解决方案很好地工作在大多数情况下,使用了著名的 LatLngBounds.Builder CameraUpdateFactory.newLatLngBounds map.animateCamera

I have a current solution working nicely for most cases, using the well-known LatLngBounds.Builder, CameraUpdateFactory.newLatLngBounds and map.animateCamera.

我有一些情况下,这给问题,但:当点太远,对这些点的重心最大缩放级别的地图中心。例如:我有10个在法国和2个夏威夷。地图中心或多或少的caribeans在最小缩放级别。因此,在我得到了什么都不显示屏幕,用户滚动到实际看到的东西是存在的。

I have some cases which give problems though: when the points are too far away, the map centers on max zoom level on the barycenter of those points. For example: I have 10 points in France and 2 points in Hawai. Maps centers more or less on the caribeans at min zoom level. Hence on screen I got nothing shown, the user has to scroll to actually see something is there.

所以我的问题是:

有没有办法让地图缩小远远不够,这样我可以看到所有的点(这将是prefered)

is there a way to get the map to zoom out far enough so that I can see all points (that would be prefered)

或者:这将是过滤掉这些情况下,只有几个点很远的多数,并选择一个设定点的放大的(在我的例子中,最好的方法,我会选择缩小在10在法国分,忘记在夏威夷的那些)。

Or: which would be the best way to filter out those cases where just a few points are very far away from the majority and pick a set of point to zoom on (in my example, I would choose to zoom on the 10 points in France and forget about the ones in Hawai).

推荐答案

根据一些想法来自cYrixmorten,我简单的问题,因为我知道地图可以容纳至少4000公里的表面。因此,这里是建忽略摄像头(当时我根本不理会这摄像头的摄像头范围计算,但仍增加了标记,以便它是地图,如果用户对移动)。

Based on some ideas from cYrixmorten, I have simplified the problem because I know the map can accomodate at least 4000km of surface. So here is the function to build the list of ignored webcams (then I simply ignore that webcam for the camera bounds computation but still add the marker so that it is on the map if the user moves).

private List<Webcam> buildIgnoredWebcamsList(List<Webcam> webcams) {
    if (webcams == null || webcams.size() < 2) return Lists.newArrayList();

    int webcamCount = webcams.size();

    // Number of conflicts (distance > 4000 km) for the camera at index #
    float averageConflictCount = 0;
    int[] conflictCount = new int[webcamCount];
    Arrays.fill(conflictCount, 0);

    // Find number of conflicts between camera pairs
    float[] distance = new float[1];

    for (int i = 0; i < webcamCount - 1; ++i) {
        Webcam a = webcams.get(i);

                    // We don't have to start from 0, compare a and b only once
        for (int j = i + 1; j < webcamCount; ++j) {
            Webcam b = webcams.get(j);
            Location.distanceBetween(a.getLatitude(), a.getLongitude(), b.getLatitude(), b.getLongitude(), distance);

            // We have a conflict between a and b if they are more than 4000km away
            if (distance[0] > 4000 * 1000) {
                conflictCount[i] += 1;
                conflictCount[j] += 1;
                averageConflictCount += 2;
            }
        }
    }
    averageConflictCount /= webcamCount;

    // Exclude all webcams with a number of conflicts greater than the average
    List<Webcam> ignoredCamerasForBounds = Lists.newArrayList();

    for (int i = 0; i < webcamCount; ++i) {
        if (conflictCount[i] > averageConflictCount) {
            ignoredCamerasForBounds.add(webcams.get(i));
        }
    }

    return ignoredCamerasForBounds;
}

这篇关于Android地图V2 - 动画的相机,包括最标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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