【问题标题】:How to animateCamera at run time in Map V2如何在 Map V2 中运行时为相机设置动画
【发布时间】:2013-08-10 13:13:38
【问题描述】:

我是 android 新手,我正在制作具有 Google Map V2 的应用程序。我想在运行时对相机缩放值进行动画处理。它应该取决于当前位置(经纬度)和目的地位置(目的地纬度和经度)。

它应该是缩放,这样它应该尽可能地显示两个标记,并且不需要在 mapv2 上进行任何平移、放大/缩小手势。

我使用了这段代码,但我需要平移手势才能在地图上看到这两个市场。我希望它应该尽可能接近默认值,并且不需要任何平移手势。

map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 12.0f));

提前致谢。

【问题讨论】:

    标签: android


    【解决方案1】:

    你需要使用newLatLngBounds()

    Returns a CameraUpdate that transforms the camera such that the specified latitude/longitude bounds are centered on screen at the greatest possible zoom level. You can specify padding, in order to inset the bounding box from the map view's edges. The returned CameraUpdate has a bearing of 0 and a tilt of 0.

    找出2个点的边界框,给出最西南点和最东北点

    示例:

    map.animateCamera(CameraUpdateFactory.newLatLngBounds(new LatLngBounds(southWest,northEast),10));
    

    要获得边界框,您需要遍历点并找到最大/最小 lat/lng

    示例:

    for(//for loop){
        LatLng point = new LatLng(lat,lng)
    
        if(point.getLatitude() > maxLat){
            maxLat = point.getLatitude();
        }
        if(point.getLatitude() < minLat){
            minLat = point.getLatitude();
        }
        if(point.getLongitude() > maxLon){
            maxLon = point.getLongitude();
        }
        if(point.getLongitude() < minLon){
            minLon = point.getLongitude();
        }
    }
    
    northEast = new LatLng(maxLat,maxLon);
    southWest = new LatLng(minLat,minLon);
    

    【讨论】:

    • 如何到达西南、东北?我有四个坐标当前位置和目的地位置经纬度
    • 对不起,我还是看不懂代码。 for 循环的使用以及 maxLat、minLat、maxlon、minLon 的初始值
    • 只需遍历你的 2 个点,找到最大纬度、最小纬度、最大经度和最小经度
    • 我得到这个异常 08-09 00:16:16.554: E/AndroidRuntime(28998): Caused by: java.lang.IllegalStateException: Map size should not be 0. 很可能,布局有地图视图尚未发生。
    • 您正试图在地图显示之前移动地图,我遇到了同样的问题。在这里查看我的问题以获得建议的解决方案,您基本上需要等到视图加载才能移动地图stackoverflow.com/questions/17820617/…
    猜你喜欢
    • 2012-12-02
    • 2023-04-08
    • 2019-12-06
    • 1970-01-01
    • 1970-01-01
    • 2013-08-26
    • 2016-08-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多